如何获取CMFCRibbonComboBox的按键关闭通知? [英] How to get notification for keydown for CMFCRibbonComboBox?

查看:99
本文介绍了如何获取CMFCRibbonComboBox的按键关闭通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ribonbar上有CMFCRibbonComboBox,并且我希望当该用户按下打开的下拉列表并选择与用户按下的字符相对应的项.

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.

我该怎么做? 谢谢

推荐答案

我在MSDN

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

C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ VC \ atlmfc \ src \ mfc \ afxribbonedit.cpp 的本地副本保存到项目中

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

BOOL CMFCRibbonRichEditCtrl::PreTranslateMessage(MSG* pMsg)中替换为

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

与此

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;
        }

对于下拉列表(而不是下拉列表),您可以类似地将WM_CHAR交给基于当前位置之后的下一个项目的第一个字母搜索.请注意,如果将来在功能区库中进行任何更新,都需要检查上述黑客行为,并在功能区库中正确实现后将其丢弃.

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.

这篇关于如何获取CMFCRibbonComboBox的按键关闭通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆