Getting the handle of the currently focused control inside another application

[亡魂溺海] 提交于 2019-12-11 05:16:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!