Upravit

Sdílet prostřednictvím


GetFocus function (winuser.h)

Retrieves the handle to the window that has the keyboard focus, if the window is attached to the calling thread's message queue.

Syntax

HWND GetFocus();

Return value

Type: HWND

The return value is the handle to the window with the keyboard focus. If the calling thread's message queue does not have an associated window with the keyboard focus, the return value is NULL.

Remarks

GetFocus returns the window with the keyboard focus for the current thread's message queue. If GetFocus returns NULL, another thread's queue may be attached to a window that has the keyboard focus.

Use the GetForegroundWindow function to retrieve the handle to the window with which the user is currently working. You can associate your thread's message queue with the windows owned by another thread by using the AttachThreadInput function.

To get the window with the keyboard focus on the foreground queue or the queue of another thread, use the GetGUIThreadInfo function.

Examples

For an example, see "Creating a Combo Box Toolbar" in Using Combo Boxes.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll
API set ext-ms-win-ntuser-window-l1-1-4 (introduced in Windows 10, version 10.0.14393)

See also

AttachThreadInput

Conceptual

GetForegroundWindow

GetGUIThreadInfo

Keyboard Input

Other Resources

Reference

SetFocus

WM_KILLFOCUS

WM_SETFOCUS