WinSetWindowPos
Appearance
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