Example #1
0
LRESULT SpeedPage::onSpeedChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& /*bHandled*/)
{
	tstring speed;
	speed.resize(1024);
	speed.resize(GetDlgItemText(wID, &speed[0], 1024));
	if (!speed.empty() && wNotifyCode != CBN_SELENDOK) {
		boost::wregex reg;
		if(speed[speed.size() -1] == '.')
			reg.assign(_T("(\\d+\\.)"));
		else
			reg.assign(_T("(\\d+(\\.\\d+)?)"));
		if (!regex_match(speed, reg)) {
			CComboBox tmp;
			tmp.Attach(hWndCtl);
			DWORD dwSel;
			if ((dwSel = tmp.GetEditSel()) != CB_ERR) {
				tstring::iterator it = speed.begin() +  HIWORD(dwSel)-1;
				speed.erase(it);
				tmp.SetEditSel(0,-1);
				tmp.SetWindowText(speed.c_str());
				tmp.SetEditSel(HIWORD(dwSel)-1, HIWORD(dwSel)-1);
				tmp.Detach();
			}
		}
	}

	updateValues(wNotifyCode);
	validateMCNLimits(wNotifyCode);
	return TRUE;
}
Example #2
0
void CAutoComplete::DoCompletion(CWnd* pWnd, CString s,
								 const CStringArray& arMatches)
								 
{
	
	if (m_iType==ComboBox)
	{
		
		// 这种强制转换从技术上讲是不正确的,但它是一个标准的MFC诀窍.
		
		CComboBox* pComboBox = (CComboBox*)pWnd;
		
		// 更新下拉框以反映可能的匹配
		
		pComboBox->ResetContent();

		
		for (int i=0; i <arMatches.GetSize();i++)
			
			pComboBox->AddString(arMatches[i]);
		
		// 用户箭头光标,这样用户才能选择
		
		::SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW)));
		
		// 显示下拉框
		
		pComboBox->ShowDropDown();
		
		pComboBox->SetWindowText(IgnoreCompletion(s) ? s : arMatches[0]);
		
		pComboBox->SetEditSel(s.GetLength(),-1);  //设置高亮
		
	} 
	else if (m_iType==Edit && !IgnoreCompletion(s)) 
	{
		
		// 这种强制转换从技术上讲是不正确的,但它是一个标准的MFC诀窍.
		
		CEdit* pEdit = (CEdit*)pWnd;
		
		pEdit->SetWindowText(arMatches[0]);
		
		pEdit->SetSel(s.GetLength(),-1);
		
	}

}