How to get key-down message in a WTL combobox?
-
Hello everyone: I have a WTL combobox class, but when clicked Enter key, the combobox can not get the key down message, how to get it? Please help me. BTW, I put the combobox in a dialog box and add "WM_KEYDOWN" to the combobox class, but it cannot get this message. -Freehawk
-
Hello everyone: I have a WTL combobox class, but when clicked Enter key, the combobox can not get the key down message, how to get it? Please help me. BTW, I put the combobox in a dialog box and add "WM_KEYDOWN" to the combobox class, but it cannot get this message. -Freehawk
Take a look at WM_GETDLGCODE[^] -- Booohoo!
-
Hello everyone: I have a WTL combobox class, but when clicked Enter key, the combobox can not get the key down message, how to get it? Please help me. BTW, I put the combobox in a dialog box and add "WM_KEYDOWN" to the combobox class, but it cannot get this message. -Freehawk
Sorry for late response. Subclass the edit part of combo and catch WM_KEYDOWN from it. in .h file:
CContainedWindow m_Edit; ... BEGIN_MSG_MAP(CYourClass) ... ALT_MSG_MAP(1) MESSAGE_HANDLER(WM_GETDLGCODE, OnGetDlgCode) MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown) MESSAGE_HANDLER(WM_CHAR, OnEditInputMagnification) ... END_MSG_MAP()
in .cpp file: in constructor:CYourClass::CYourClass() : m_Edit(_T("EDIT"), this, 1) {}
in OnInitDialog:m_Edit.SubclassWindow(::GetWindow(GetDlgItem(IDC_COMBO), GW_CHILD));
add if you want all keys add following:LRESULT CYourClass::OnGetDlgCode(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { return DLGC_WANTALLKEYS; }
and finally you can get KeyDown:LRESULT CYourClass::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { switch (wParam) { case VK_RETURN: { ... } break; case VK_TAB: { ... } break; } bHandled = FALSE; return S_OK; }
-
Sorry for late response. Subclass the edit part of combo and catch WM_KEYDOWN from it. in .h file:
CContainedWindow m_Edit; ... BEGIN_MSG_MAP(CYourClass) ... ALT_MSG_MAP(1) MESSAGE_HANDLER(WM_GETDLGCODE, OnGetDlgCode) MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown) MESSAGE_HANDLER(WM_CHAR, OnEditInputMagnification) ... END_MSG_MAP()
in .cpp file: in constructor:CYourClass::CYourClass() : m_Edit(_T("EDIT"), this, 1) {}
in OnInitDialog:m_Edit.SubclassWindow(::GetWindow(GetDlgItem(IDC_COMBO), GW_CHILD));
add if you want all keys add following:LRESULT CYourClass::OnGetDlgCode(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { return DLGC_WANTALLKEYS; }
and finally you can get KeyDown:LRESULT CYourClass::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { switch (wParam) { case VK_RETURN: { ... } break; case VK_TAB: { ... } break; } bHandled = FALSE; return S_OK; }