Microsoft Windows CE 3.0  

SetFocus

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This function sets the keyboard focus to the specified window. All subsequent keyboard input is directed to this window. The window, if any, that previously had the keyboard focus loses it.

HWND
SetFocus(
HWND
hWnd
);

Parameters

hWnd
[in] Handle to the window that will receive the keyboard input. If this parameter is NULL, keystrokes are ignored.

Return Values

The handle to the window that previously had the keyboard focus indicates success. NULL indicates that the hWndparameter is invalid or the window is not associated with the calling thread's message queue. To get extended error information, call GetLastError.

Remarks

The SetFocusfunction sends a WM_KILLFOCUSmessage to the window that loses the keyboard focus and a WM_SETFOCUSmessage to the window that receives the keyboard focus. It also activates either the window that receives the focus or the parent of the window that receives the focus.

If a window is active but does not have the focus, any key pressed will produce the WM_SYSCHAR, WM_SYSKEYDOWN, or WM_SYSKEYUPmessage. If the VK_MENU key is also pressed, the lParamparameter of the message will have bit 30 set. Otherwise, the messages produced do not have this bit set.

Do not use the SetFocusfunction to set the keyboard focus to a window associated with another thread's message queue. There is one exception. If a window on one thread is the child of the window on the other thread, or if the windows are siblings of the same parent, the thread associated with one window can set the focus to the other window even though it belongs to a different thread. In this case, there is no need to call AttachThreadInputfirst.

Requirements

Runs on Versions Defined in Include Link to
Windows CE OS 1.0 and later Winuser.h   Caret.lib, Foregnd.lib
Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

GetActiveWindow, GetFocus, GetLastError, SetActiveWindow, SetCapture, SetForegroundWindow, WM_KILLFOCUS, WM_SETFOCUS, WM_SYSCHAR, WM_SYSKEYDOWN, WM_SYSKEYUP