It works with CBS_DROPDOWNLIST style
Otherwise, it is received by the Edit part
KEYDOWN in COMBOBOX does not work
I need to have access to the KEYDOWN event in all the visual controls of the window, and in the instructions indicated on the next page:
https://video2.skills-academy.com/en-us/windows/win32/controls/subclass-a-combo-box
Everything works, except that the KEYDOWN event does not fire in any function.
Regards
Daniel de Dios "El Ignorado"
daniel.dedios@Karima ben .com
2 answers
Sort by: Most helpful
-
Castorix31 82,751 Reputation points
2020-08-11T16:57:45.973+00:00 -
Rita Han - MSFT 2,161 Reputation points
2020-08-12T06:30:21.343+00:00 Hello,
Everything works, except that the KEYDOWN event does not fire in any function.
It seems the wrong window handle is passed to
SetWindowLongPtr
. ThehwndEdit1
is actual window handle of combobox itself instead of its edit control.Change
pt.x = 1; pt.y = 1;
to
pt.x = 3; pt.y = 3;
will work.
More precise solution is using GetComboBoxInfo function to get window handle of edit control. hwndItem is the handle to the edit box.
COMBOBOXINFO cbInfo; cbInfo.cbSize = sizeof(COMBOBOXINFO); GetComboBoxInfo(hwndCombo1, &cbInfo); lpfnEditWndProc = (WNDPROC)SetWindowLongPtr(cbInfo.hwndItem, GWLP_WNDPROC, (LONG_PTR)SubClassProc);
Thank you!