Jump to content

WinSetWindowPos: Difference between revisions

From EDM2
Created page with "This function allows the general positioning of a window. Note: Messages may be received from other processes or threads during the processing of this function. ==Syntax==..."
 
Ak120 (talk | contribs)
mNo edit summary
 
Line 1: Line 1:
This function allows the general positioning of a window.  
This function allows the general positioning of a window.


Note: Messages may be received from other processes or threads during the processing of this function.  
Note: Messages may be received from other processes or threads during the processing of this function.


==Syntax==
==Syntax==
  WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
  WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl)


==Parameters==
==Parameters==
;hwnd (HWND) - input  
;hwnd (HWND) - input:Window handle.
:Window handle.  
;hwndInsertBehind (HWND) - input:Relative window-placement order.
 
:Ignored if SWP_ZORDER is not selected. Values that can be specified are:
;hwndInsertBehind (HWND) - input  
::HWND_TOP - Place hwnd on top of all siblings
:Relative window-placement order.  
::HWND_BOTTOM - Place hwnd behind all siblings
 
::Other - Identifies the sibling window behind which hwnd is to be placed.
:Ignored if SWP_ZORDER is not selected. Values that can be specified are:  
;x (LONG) - input:Window position, x-coordinate.
 
:This is the x-coordinate of hwnd. It is in window coordinates relative to the bottom left corner of its parent, but is ignored if SWP_MOVE is not selected.
:HWND_TOP  
;y (LONG) - input:Window position, y-coordinate.
::Place hwnd on top of all siblings  
:This is the y-coordinate of hwnd. It is in window coordinates relative to the bottom left corner of its parent, but is ignored if SWP_MOVE is not selected.
:HWND_BOTTOM  
;cx (LONG) - input:Window size.
::Place hwnd behind all siblings  
:This specifies the width of hwnd in device units, but is ignored if SWP_SIZE is not selected.
:Other  
;cy (LONG) - input:Window size.  
::Identifies the sibling window behind which hwnd is to be placed.  
:This specifies the depth of hwnd in device units, but is ignored if SWP_SIZE is not selected.
 
;fl (ULONG) - input:Window-positioning options.
;x (LONG) - input  
:One or more of these options can be specified:
:Window position, x-coordinate.  
::SWP_SIZE - Change the window size.
 
::SWP_MOVE - Change the window x,y position.
:This is the x-coordinate of hwnd. It is in window coordinates relative to the bottom left corner of its parent, but is ignored if SWP_MOVE is not selected.  
::SWP_ZORDER - Change the relative window placement.
 
::SWP_SHOW - Show the window.
;y (LONG) - input  
::SWP_HIDE - Hide the window.
:Window position, y-coordinate.  
::SWP_NOREDRAW - Changes are not redrawn.
 
::SWP_NOADJUST - Do not send a WM_ADJUSTWINDOWPOS message before moving or sizing.
:This is the y-coordinate of hwnd. It is in window coordinates relative to the bottom left corner of its parent, but is ignored if SWP_MOVE is not selected.  
::SWP_ACTIVATE - Activate the hwnd window if it is a frame window. This indicator has no effect on other windows.
 
;cx (LONG) - input  
:Window size.  
 
:This specifies the width of hwnd in device units, but is ignored if SWP_SIZE is not selected.  
 
;cy (LONG) - input  
:Window size.  
 
:This specifies the depth of hwnd in device units, but is ignored if SWP_SIZE is not selected.  
 
;fl (ULONG) - input  
:Window-positioning options.  
 
:One or more of these options can be specified:  
 
:SWP_SIZE  
::Change the window size.  
 
:SWP_MOVE  
::Change the window x,y position.  
 
:SWP_ZORDER  
::Change the relative window placement.  
 
:SWP_SHOW  
::Show the window.  
 
:SWP_HIDE  
::Hide the window.  
 
:SWP_NOREDRAW  
::Changes are not redrawn.  
 
:SWP_NOADJUST  
::Do not send a WM_ADJUSTWINDOWPOS message before moving or sizing.  
 
:SWP_ACTIVATE  
::Activate the hwnd window if it is a frame window. This indicator has no effect on other windows.  
 
::The frame window is made the topmost window, unless SWP_ZORDER is specified also in which instance the hwndInsertBehind window is used.  
::The frame window is made the topmost window, unless SWP_ZORDER is specified also in which instance the hwndInsertBehind window is used.  
 
::SWP_DEACTIVATE - Deactivate the hwnd window if it is a frame window. This indicator has no effect on other windows.
:SWP_DEACTIVATE  
::The frame window is made the bottommost window, unless SWP_ZORDER is specified, in which instance the hwndInsertBehind window is used.
::Deactivate the hwnd window if it is a frame window. This indicator has no effect on other windows.  
::SWP_MINIMIZE - Minimize the window. This indicator has no effect if the window is in a minimized state, and is also mutually exclusive with SWP_MAXIMIZE and SWP_RESTORE.
 
::SWP_MAXIMIZE - Maximize the window. This indicator has no effect if the window is in a maximized state, and is also mutually exclusive with SWP_MINIMIZE and SWP_RESTORE.
::The frame window is made the bottommost window, unless SWP_ZORDER is specified, in which instance the hwndInsertBehind window is used.  
::SWP_RESTORE - Restore the window. This indicator has no effect if the window is in its normal state, and is also mutually exclusive with SWP_MINIMIZE and SWP_MAXIMIZE.
 
::The position and size of the window in its normal state is remembered in its window words when it is first maximized or minimized, although these values can be altered by use of the WinSetWindowUShort function.
:SWP_MINIMIZE  
::The window is restored to the position and size remembered in its window words, unless the SWP_MOVE or SWP_SIZE indicators are set. These indicators cause the position and size values specified in this function to be used.
::Minimize the window. This indicator has no effect if the window is in a minimized state, and is also mutually exclusive with SWP_MAXIMIZE and SWP_RESTORE.  
 
:SWP_MAXIMIZE  
::Maximize the window. This indicator has no effect if the window is in a maximized state, and is also mutually exclusive with SWP_MINIMIZE and SWP_RESTORE.  
 
:SWP_RESTORE  
::Restore the window. This indicator has no effect if the window is in its normal state, and is also mutually exclusive with SWP_MINIMIZE and SWP_MAXIMIZE.  
 
::The position and size of the window in its normal state is remembered in its window words when it is first maximized or minimized, although these values can be altered by use of the WinSetWindowUShort function.  
 
::The window is restored to the position and size remembered in its window words, unless the SWP_MOVE or SWP_SIZE indicators are set. These indicators cause the position and size values specified in this function to be used.  


==Returns==
==Returns==
;rc (BOOL) - returns  
;rc (BOOL) - returns:Repositioning indicator.
Repositioning indicator.  
::TRUE - Window successfully repositioned
 
::FALSE - Window not successfully repositioned.
;TRUE  
:Window successfully repositioned  
;FALSE  
:Window not successfully repositioned.  


==ERRORS==
==ERRORS==
Possible returns from WinGetLastError  
Possible returns from WinGetLastError:
 
;PMERR_INVALID_HWND (0x1001):An invalid window handle was specified.
;PMERR_INVALID_HWND (0x1001)  
;PMERR_INVALID_FLAG (0x1019):An invalid bit was set for a parameter. Use constants defined by PM for options, and do not set any reserved bits.
:An invalid window handle was specified.  
 
;PMERR_INVALID_FLAG (0x1019)  
:An invalid bit was set for a parameter. Use constants defined by PM for options, and do not set any reserved bits.  


==Example Code==
==Example Code==
Line 125: Line 66:
     winpos.x,                                      /* x pos */
     winpos.x,                                      /* x pos */
     winpos.y,                                      /* y pos */
     winpos.y,                                      /* y pos */
     winpos.cx,                                     /* x size */
     winpos.cx,                                     /* x size */
     winpos.cy,                                     /* y size */
     winpos.cy,                                     /* y size */
     SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW); /* flags*/
     SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW); /* flags*/
</PRE>
</PRE>
Line 146: Line 87:
rc = WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
rc = WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
</PRE>
</PRE>
==Related Functions==
==Related Functions==
*WinGetMinPosition  
*WinGetMinPosition  
Line 161: Line 103:
*WM_ERASEBACKGROUND  
*WM_ERASEBACKGROUND  
*WM_MOVE  
*WM_MOVE  
*WM_SIZE  
*WM_SIZE


[[Category:Win]]
[[Category:Win]]

Latest revision as of 10:12, 5 April 2025

This function allows the general positioning of a window.

Note: Messages may be received from other processes or threads during the processing of this function.

Syntax

WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl)

Parameters

hwnd (HWND) - input
Window handle.
hwndInsertBehind (HWND) - input
Relative window-placement order.
Ignored if SWP_ZORDER is not selected. Values that can be specified are:
HWND_TOP - Place hwnd on top of all siblings
HWND_BOTTOM - Place hwnd behind all siblings
Other - Identifies the sibling window behind which hwnd is to be placed.
x (LONG) - input
Window position, x-coordinate.
This is the x-coordinate of hwnd. It is in window coordinates relative to the bottom left corner of its parent, but is ignored if SWP_MOVE is not selected.
y (LONG) - input
Window position, y-coordinate.
This is the y-coordinate of hwnd. It is in window coordinates relative to the bottom left corner of its parent, but is ignored if SWP_MOVE is not selected.
cx (LONG) - input
Window size.
This specifies the width of hwnd in device units, but is ignored if SWP_SIZE is not selected.
cy (LONG) - input
Window size.
This specifies the depth of hwnd in device units, but is ignored if SWP_SIZE is not selected.
fl (ULONG) - input
Window-positioning options.
One or more of these options can be specified:
SWP_SIZE - Change the window size.
SWP_MOVE - Change the window x,y position.
SWP_ZORDER - Change the relative window placement.
SWP_SHOW - Show the window.
SWP_HIDE - Hide the window.
SWP_NOREDRAW - Changes are not redrawn.
SWP_NOADJUST - Do not send a WM_ADJUSTWINDOWPOS message before moving or sizing.
SWP_ACTIVATE - Activate the hwnd window if it is a frame window. This indicator has no effect on other windows.
The frame window is made the topmost window, unless SWP_ZORDER is specified also in which instance the hwndInsertBehind window is used.
SWP_DEACTIVATE - Deactivate the hwnd window if it is a frame window. This indicator has no effect on other windows.
The frame window is made the bottommost window, unless SWP_ZORDER is specified, in which instance the hwndInsertBehind window is used.
SWP_MINIMIZE - Minimize the window. This indicator has no effect if the window is in a minimized state, and is also mutually exclusive with SWP_MAXIMIZE and SWP_RESTORE.
SWP_MAXIMIZE - Maximize the window. This indicator has no effect if the window is in a maximized state, and is also mutually exclusive with SWP_MINIMIZE and SWP_RESTORE.
SWP_RESTORE - Restore the window. This indicator has no effect if the window is in its normal state, and is also mutually exclusive with SWP_MINIMIZE and SWP_MAXIMIZE.
The position and size of the window in its normal state is remembered in its window words when it is first maximized or minimized, although these values can be altered by use of the WinSetWindowUShort function.
The window is restored to the position and size remembered in its window words, unless the SWP_MOVE or SWP_SIZE indicators are set. These indicators cause the position and size values specified in this function to be used.

Returns

rc (BOOL) - returns
Repositioning indicator.
TRUE - Window successfully repositioned
FALSE - Window not successfully repositioned.

ERRORS

Possible returns from WinGetLastError:

PMERR_INVALID_HWND (0x1001)
An invalid window handle was specified.
PMERR_INVALID_FLAG (0x1019)
An invalid bit was set for a parameter. Use constants defined by PM for options, and do not set any reserved bits.

Example Code

This example uses the recommended size, position and status from the WinQueryTaskSize call to position the first window of a newly-started application (typically the main window).

#define INCL_WINSWITCHLIST
#define INCL_WINFRAMEMGR
#include <OS2.H>

HAB  hab;
SWP  winpos;
HWND hwndFrame;

WinQueryTaskSizePos(hab, 0, &winpos);

 WinSetWindowPos(hwndFrame, HWND_TOP,
     winpos.x,                                       /* x pos */
     winpos.y,                                       /* y pos */
     winpos.cx,                                     /* x size */
     winpos.cy,                                     /* y size */
     SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW); /* flags*/

Definition

#define INCL_WINWINDOWMGR /* Or use INCL_WIN, INCL_PM, */
#include <os2.h>

HWND     hwnd;              /*  Window handle. */
HWND     hwndInsertBehind;  /*  Relative window-placement order. */
LONG     x;                 /*  Window position, x-coordinate. */
LONG     y;                 /*  Window position, y-coordinate. */
LONG     cx;                /*  Window size. */
LONG     cy;                /*  Window size. */
ULONG    fl;                /*  Window-positioning options. */
BOOL     rc;                /*  Repositioning indicator. */

rc = WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);

Related Functions

  • WinGetMinPosition
  • WinQueryActiveWindow
  • WinQueryWindowPos
  • WinSaveWindowPos
  • WinSetActiveWindow
  • WinSetMultWindowPos
  • WinSetWindowPos

Related Messages

  • WM_ACTIVATE
  • WM_ADJUSTWINDOWPOS
  • WM_CALCVALIDRECTS
  • WM_ERASEBACKGROUND
  • WM_MOVE
  • WM_SIZE