WinSetFocus
Appearance
This function sets the focus window.
Syntax
WinSetFocus(hwndDeskTop, hwndNewFocus)
Parameters
- hwndDeskTop (HWND) - input
- Desktop-window handle.
- HWND_DESKTOP - The desktop-window handle
- Other - Specified desktop-window handle.
- hwndNewFocus (HWND) - input
- Window handle to receive the focus.
- If hwndNewFocus identifies a desktop window, no window on the device associated with the hwndDeskTop receives the focus.
Returns
- rc (BOOL) - returns
- Success indicator.
- TRUE - Successful completion
- FALSE - Error occurred.
Errors
Possible returns from WinGetLastError
- PMERR_INVALID_HWND (0x1001)
- An invalid window handle was specified.
- PMERR_CANNOT_SET_FOCUS (0x1037)
- Focus cannot be set if a focus change is in progress, or if a system-modal window exists.
Remarks
This function is equivalent to the WinFocusChange call in which the flFocusChange parameter is set to 0.
If no window has the input focus, WM_CHAR messages are posted to the queue of the active window and are not thrown away.
When this function is called a WM_MOUSEMOVE message is posted regardless of whether the pointing device pointer has actually moved. This ensures that the window below the pointing device, at that time, is able to change features, such as the shape of the pointing device pointer.
This function requires the existence of a message queue.
Example Code
This example gives the client the focus if it does not already have it.
#define INCL_WININPUT #include <os2.h> #define SYS_MENU 900 HWND hwndFrame; if (WinQueryFocus(HWND_DESKTOP) != /* returns handle of */ /* window with focus. */ WinWindowFromID(hwndFrame,FID_CLIENT)) { WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwndFrame,FID_CLIENT)); /* handle of client */ }
Related Functions
- WinEnablePhysInput
- WinFocusChange
- WinGetKeyState
- WinGetPhysKeyState
- WinQueryFocus
- WinSetKeyboardStateTable
Related Messages
- WM_CHAR
- WM_MOUSEMOVE