KEYDOWN in COMBOBOX does not work

Daniel de Dios El Ignorado 1 Reputation point
2020-08-11T16:39:57.38+00:00

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

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,498 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 82,751 Reputation points
    2020-08-11T16:57:45.973+00:00

    It works with CBS_DROPDOWNLIST style
    Otherwise, it is received by the Edit part

    1 person found this answer helpful.
    0 comments No comments

  2. 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. The hwndEdit1 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!

    1 person found this answer helpful.
    0 comments No comments