0
votes

I have a large C++ legacy appliaction using MFC.

In different places throughout the UI (views, dialogs, custom controls derived from CWnd) I get the WM_KEYDOWN message to copy some information to the clipboard for testing purposes. For instance the content of grid/list in a specific moment.

I would like to use a keyboard hook to centralize the implementation of all this testing hooks but I don't know how to get the window that will eventually get the WM_KEYDOWN message.

For instance if user press Ctrl+I in a grid control (the focus is in the control itself) I want to call a function in the grid that copy information of the grid (row, cols, etc.) to the clipboard. But if the focus is in anyother control of the dialog I want to call a method of the dialog exporting information of the dialog.

This is the syntax of the callback:

LRESULT CALLBACK KeyboardProc( In int code, In WPARAM wParam, In LPARAM lParam );

But there is no information of the CWnd that has the focus and therfore will get the key down message.

1
I would suggest registering a system wide message that all your classes can respond to appropriately. That way you don't need to know any function names you just send the message to the window with the focus.user1793036

1 Answers

1
votes

Your best option is to install another hook to monitor the setting of the focus on a window. Using CBTProc and listening for HCBT_SETFOCUS will allow you to determine the window that is about to get the focus. Since the handle to the window gaining the focus is provided as part of that hook, you can store it away for use with your other hook.