Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
User Input
Keyboard Input
Functions
 GetFocus Function

  Switch on low bandwidth view
GetFocus Function

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.

Syntax

HWND GetFocus(VOID);

Return Value

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.

Windows 98/Me and Windows NT 4.0 SP3 and later: To get the window with the keyboard focus on the foreground queue or the queue of another thread, use the GetGUIThreadInfo function.

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

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 3.1

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
vb.net syntax      dmex   |   Edit   |   Show History
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetFocus() As IntPtr End Function
Tags What's this?: Add a tag
Flag as ContentBug
C# syntax      dmex   |   Edit   |   Show History
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetFocus();
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker