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..."
 
Ak120 (talk | contribs)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
This function sets the focus window.
This function sets the focus window.
==Syntax==
==Syntax==
;hwndDeskTop (HWND) - input
WinSetFocus(hwndDeskTop, hwndNewFocus)
:Desktop-window handle.
:;HWND_DESKTOP
::The desktop-window handle Other
::Specified desktop-window handle.


:;hwndNewFocus (HWND) - input
==Parameters==
::Window handle to receive the focus.
;hwndDeskTop ([[HWND]]) - input:Desktop-window handle.
::If hwndNewFocus identifies a desktop window, no window on the device associated with the hwndDeskTop receives the focus.  
::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==
==Returns==
;rc (BOOL) - returns:Success indicator.
::TRUE - Successful completion
::FALSE - Error occurred.


==Errors==
==Errors==
Possible returns from WinGetLastError
Possible returns from WinGetLastError
;PMERR_INVALID_HWND (0x1001)
;PMERR_INVALID_HWND (0x1001):An invalid window handle was specified.
: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.
;PMERR_CANNOT_SET_FOCUS (0x1037)
 
:Focus cannot be set if a focus change is in progress, or if a system-modal window exists.
==Remarks==
==Remarks==
This function is equivalent to the WinFocusChange call in which the flFocusChange parameter is set to 0.
This function is equivalent to the WinFocusChange call in which the flFocusChange parameter is set to 0.
Line 33: Line 28:
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.
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.  
This function requires the existence of a message queue.
 
==Example Code==
==Example Code==
This example gives the client the focus if it does not already have it.
This example gives the client the focus if it does not already have it.
<pre>
<pre>
#define INCL_WININPUT
#define INCL_WININPUT
#include <OS2.H>
#include <os2.h>
 
#define SYS_MENU 900
#define SYS_MENU 900
HWND hwndFrame;
HWND hwndFrame;
Line 48: Line 45:
     WinSetFocus(HWND_DESKTOP,
     WinSetFocus(HWND_DESKTOP,
     WinWindowFromID(hwndFrame,FID_CLIENT));  /* handle of client */
     WinWindowFromID(hwndFrame,FID_CLIENT));  /* handle of client */
}
}
</pre>
Definition
<pre>
#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);
</pre>
</pre>


Line 73: Line 55:
* WinQueryFocus
* WinQueryFocus
* WinSetKeyboardStateTable  
* WinSetKeyboardStateTable  
==Related Messages==
==Related Messages==
* WM_CHAR
* WM_CHAR

Latest revision as of 20:00, 12 April 2024

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