如何在程序中检测是Window中的哪个控件有焦点?

来源:互联网 发布:vb.net string.format 编辑:程序博客网 时间:2024/04/27 15:10

原文网址:http://jcobra.blog.163.com/blog/static/47049320070273251433/

如果是在WinForm程序中检测,那么可以用ActiveControl来得到当前有焦点的控件信息

如果从Windows的角度来说当前系统中哪一个窗口哪一个控件有焦点,那么要用到API了:
HWND GetForegroundWindow(VOID);
The GetForegroundWindow function returns a handle to the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads

或用
HWND GetFocus(VOID);
来得到有输入焦点的窗口.


HWND GetFocus(VOID);

The GetFocus function retrieves the handle to the window that has the keyboard focus, if the window is attached to the calling thread's message queue.

原创粉丝点击