0
如何使用A-z keydown事件在Combobox中執行搜索?更糟糕的是,這是工具欄中的CMFCToolBarButton。MFC組合框,搜索字體列表
這是帶有字體列表的comboB。只需要選擇一個keydown。 謝謝!
如何使用A-z keydown事件在Combobox中執行搜索?更糟糕的是,這是工具欄中的CMFCToolBarButton。MFC組合框,搜索字體列表
這是帶有字體列表的comboB。只需要選擇一個keydown。 謝謝!
這是解決方案。 工作正常。
void C_dropDlg::OnEditUpdate()
{
if (!m_bAutoComplete)
return;
// Get the text in the edit box
CString str;
MyDropDown.GetWindowText(str);
int nLength = str.GetLength();
// Currently selected range
DWORD dwCurSel = MyDropDown.GetEditSel();
WORD dStart = LOWORD(dwCurSel);
WORD dEnd = HIWORD(dwCurSel);
// Search for, and select in, and string in the combo box that is prefixed
// by the text in the edit box
if (MyDropDown.SelectString(-1, str) == CB_ERR)
{
SetWindowText(str); // No text selected, so restore what was there before
if (dwCurSel != CB_ERR)
MyDropDown.SetEditSel(dStart, dEnd); //restore cursor postion
}
// Set the text selection as the additional text that we have added
if (dEnd < nLength && dwCurSel != CB_ERR)
MyDropDown.SetEditSel(dStart, dEnd);
else
MyDropDown.SetEditSel(nLength, -1);
}
// TODO: Add your control notification handler code here
BOOL C_dropDlg::PreTranslateMessage(MSG* pMsg)
{
// Need to check for backspace/delete. These will modify the text in
// the edit box, causing the auto complete to just add back the text
// the user has just tried to delete.
if (pMsg->message == WM_KEYDOWN)
{
m_bAutoComplete = TRUE;
int nVirtKey = (int) pMsg->wParam;
if (nVirtKey == VK_DELETE || nVirtKey == VK_BACK)
m_bAutoComplete = FALSE;
if(nVirtKey == VK_ESCAPE)
{
}
}
return CDialogEx::PreTranslateMessage(pMsg);
}
我已經失去了與解決方案的鏈接,但感謝作者。
不要忘記在基類中定義m_AutoComplete!
這個標準控制方式已經不是這樣了嗎? – 2012-07-31 14:28:43
我仍然需要從工具欄中獲取CComboBox。 Smth L CMFCRibbonButtonsGroup * pSBGroup = new CMFCRibbonButtonsGroup; CBarManager * barManager = new CBarManager(TRUE); \t CComboBox * cmb =(CComboBox *)barManager-> GetToolBar(IDR_TB_FONT24) - > GetButton(ID_FONT_COMBONAME); 但是還沒有工作 – 2012-07-31 14:32:04