Jump to content

WinSetFocus: Difference between revisions

From EDM2
Created page with "This function sets the focus window. ==Syntax== ;hwndDeskTop (HWND) - input :Desktop-window handle. :;HWND_DESKTOP ::The desktop-window handle Other ::Specified desktop-window..."
 
No edit summary
Line 1: Line 1:
This function sets the focus window.
This function sets the focus window.
==Syntax==
==Syntax==
;hwndDeskTop (HWND) - input
;hwndDeskTop ([[HWND]]) - input
:Desktop-window handle.
:Desktop-window handle.
:;HWND_DESKTOP
:;HWND_DESKTOP
::The desktop-window handle Other
::The desktop-window handle  
:;Other
::Specified desktop-window handle.  
::Specified desktop-window handle.  



Revision as of 16:09, 7 April 2024

This function sets the focus window.

Syntax

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.

Parameters

rc (BOOL) - returns
Success indicator.
TRUE
Successful completion
FALSE
Error occurred.

Returns

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 */

}

Definition

#define INCL_WININPUT /* Or use INCL_WIN, INCL_PM, Also in COMMON section */
#include <os2.h>

HWND    hwndDeskTop;   /*  Desktop-window handle. */
HWND    hwndNewFocus;  /*  Window handle to receive the focus. */
BOOL    rc;            /*  Success indicator. */

rc = WinSetFocus(hwndDeskTop, hwndNewFocus);

Related Functions

  • WinEnablePhysInput
  • WinFocusChange
  • WinGetKeyState
  • WinGetPhysKeyState
  • WinQueryFocus
  • WinSetKeyboardStateTable

Related Messages

  • WM_CHAR
  • WM_MOUSEMOVE