HWND SetFocus(hwnd) | |||||
HWND hwnd; | /* handle of window to receive focus | */ |
The SetFocus function sets the input focus to the given window. All subsequent keyboard input is directed to this window. The window, if any, that previously had the input focus loses it.
hwnd
Identifies the window to receive the keyboard input. If this parameter is NULL, keystrokes are ignored.
The return value identifies the window that previously had the input focus, if the function is successful. It is NULL if there is no such window or if the specified handle is invalid.
The SetFocus function sends a WM_KILLFOCUS message to the window that loses the input focus and a WM_SETFOCUS message to the window that receives the input 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 (that is, no window has the focus), any key pressed will produce the WM_SYSCHAR, WM_SYSKEYDOWN, or WM_SYSKEYUP message. If the VK_MENU key is also pressed, the lParam parameter of the message will have bit 30 set. Otherwise, the messages that are produced do not have this bit set.