1

I have CMFCRibbonComboBox on ribonbar and I want when that user press on a key open droplist and select Item acurding to chars that press by user.

For this purpose I want to get notification for keydown.

How can I to do it? Thanks

herzl shemuelian
  • 3,346
  • 8
  • 34
  • 49
  • Why are you trying to re-invent standard combo box functionality? – IInspectable Sep 27 '16 at 15:11
  • I will happy to any solution I can't to find how to it with standard way can you please help to me? – herzl shemuelian Sep 27 '16 at 15:21
  • @linspectable because the MFC ribbon combo box lacks much of the basic very important functionality of the normal MFC and Windows combo box such as searching. As a UI MFC ribbon has some pretty glaring omissions. – SmacL Oct 16 '16 at 11:29

1 Answers1

0

I asked a very similar question on MSDN here and eventually solved it myself with the following hack;

Save a local copy of C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\src\mfc\afxribbonedit.cpp to your project

In BOOL CMFCRibbonRichEditCtrl::PreTranslateMessage(MSG* pMsg) replace this

    case VK_DOWN:
        if (m_edit.m_bHasDropDownList && !m_edit.IsDroppedDown())
        {
            m_edit.DropDownList();
            return TRUE;
        }

with this

case VK_DOWN:
        if (m_edit.m_bHasDropDownList && !m_edit.IsDroppedDown())
        {
            m_edit.DropDownList();
            CMFCRibbonBaseElement* pRibbonBaseElement = m_edit.GetDroppedDown();
            if (pRibbonBaseElement && (pRibbonBaseElement->IsKindOf(RUNTIME_CLASS(CMFCRibbonComboBox))))
            {
                CString str;
                GetWindowText(str);
                CMFCRibbonComboBox *pCombo = (CMFCRibbonComboBox*)pRibbonBaseElement;
                int ItemNo = -1;
                for (int i = 0; i < pCombo->GetCount(); i++)
                {
                    CString ItemText = pCombo->GetItem(i);
                    if (ItemText.Left(str.GetLength()).CompareNoCase(str) == 0)
                    {
                        ItemNo = i;
                        break;
                    }
                }
                if (ItemNo != -1)
                {
                    pCombo->OnSelectItem(ItemNo);
                    // Draw and redraw dropdown for selection to show
                    m_edit.DropDownList();
                    m_edit.DropDownList();
                }
            }
            return TRUE;
        }

For drop lists (as opposed to drop downs) you can similarly hand WM_CHAR to do a first letter search based on the next item after the current position. Note that the above hack would need to be checked against any future updates to the ribbon library and should be dumped once it has been properly implemented in the library.

SmacL
  • 22,555
  • 12
  • 95
  • 149