问题
How would one retrieve the handle of the control that currently has focus ? I am using WH_KEYBOARD_LL to capture all keypresses in, and I should be able to determine in which textbox the user is typing in. The code capturing the events has no direct access to the controls in the other application.
I know the win32 function GetFocus() exists for getting the current window handle, but I need something similar for the current control.
Any ideas would be appreciated.
Pika
回答1:
You can pass the GUI thread ID to GetGUIThreadInfo() which will provide you with a GUITHREADINFO.hwndFocus
.
回答2:
You can use more general WH_MSGFILTER (it's called within context of the monitored thread so you must create a DLL). The callback gets MSG structure containing all informations about message (handle too).
来源:https://stackoverflow.com/questions/3333570/getting-the-handle-of-the-currently-focused-control-inside-another-application