MFC组合框,灼热字体列表

MFC combobox, searcing font list

本文关键字:字体 列表 组合 MFC      更新时间:2023-10-16

如何使用A-z keydown事件在组合框中实现搜索?更糟糕的是,工具栏中有一个CMFCToolBarButton。

这是带有字体列表的组合B。只需按下键选择一个即可。非常感谢。

这是解决方案。工作良好。

    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!