BOOL SetWindowPos(hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags) | |||||
HWND hwnd; | /* handle of window | */ | |||
HWND hwndInsertAfter; | /* placement-order handle | */ | |||
int x; | /* horizontal position | */ | |||
int y; | /* vertical position | */ | |||
int cx; | /* width | */ | |||
int cy; | /* height | */ | |||
UINT fuFlags; | /* window-positioning flags | */ |
This function changes the size, position, and ordering of child, pop-up, and top-level windows. Child, pop-up, and top-level windows are ordered according to their appearance on the screen; the topmost window receives the highest rank, and it is the first window in the list. This ordering is recorded in a window list.
hwnd
Identifies the window that will be positioned.
hwndInsertAfter
Identifies the window to precede the positioned window in the Z-order. This parameter must be a window handle or one of the following values:
Value | Meaning |
HWND_BOTTOM | ||
Places the window at the bottom of the Z-order. If hwnd identifies a topmost window, the window loses its topmost status; the system places the window at the bottom of all other windows. | ||
HWND_TOP | ||
Places the window at the top of the Z-order. | ||
HWND_TOPMOST | ||
Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated. | ||
HWND_NOTOPMOST | ||
Repositions the window to the top of all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window. |
See the following Comments section for rules about how this parameter is used.
x
Specifies the new position of the left side of the window.
y
Specifies the new position of the top of the window.
cx
Specifies the new width of the window.
cy
Specifies the new height of the window.
fuFlags
Specifies the window sizing and positioning options. This parameter can be a combination of the following values:
Value | Meaning |
SWP_DRAWFRAME | ||
Draws a frame (defined in the window's class description) around the window. | ||
SWP_FRAMECHANGED | ||
Sends a WM_NCCALCSIZE message to the window even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed. | ||
SWP_HIDEWINDOW | ||
Hides the window. | ||
SWP_NOACTIVATE | ||
Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hwndInsertAfter parameter). | ||
SWP_NOCOPYBITS | ||
Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned. | ||
SWP_NOMOVE | ||
Retains the current position (ignores the x and y parameters). | ||
SWP_NOSIZE | ||
Retains the current size (ignores the cx and cy parameters). | ||
SWP_NOREDRAW | ||
Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the non-client area (including the title and scroll bars), and any part of the parent window uncovered as a result of the moved window. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that must be redrawn. | ||
SWP_NOZORDER | ||
Retains the current ordering (ignores the hwndInsertAfter parameter). | ||
SWP_SHOWWINDOW | ||
Displays the window. |
The return value is TRUE if the function is successful or FALSE if an error occurs. To obtain extended error information, use the GetLastError function.
If the SWP_SHOWWINDOW or the SWP_HIDEWINDOW flags are set, the window cannot be moved or sized.
All coordinates for child windows are client coordinates (relative to the upper-left corner of the parent window's client area).
A window can be made a topmost window either by setting the hwndInsertAfter parameter to HWND_TOPMOST and ensuring that the SWP_NOZORDER flag is not set, or by setting a window's Z-order so that it is above any existing topmost windows. When a non-topmost window is made topmost, its owned windows are also made topmost. Its owners are not changed.
If neither SWP_NOACTIVATE nor SWP_NOZORDER is specified (that is, when the application requests that a window be simultaneously activated and placed in the specified Z-order), the value specified in hwndInsertAfter is used only in the following circumstances:
Neither HWND_TOPMOST or HWND_NOTOPMOST is specified in the hwndInsertAfter parameter.
The window specified in the hwnd parameter is not the active window.
An application cannot activate an inactive window without also bringing it to the top of the Z-order. Applications can change the Z-order of an activated window without restrictions or activate a window and then move it to the top of the topmost or non-topmost windows.
A topmost window is no longer topmost if it is repositioned to the bottom (HWND_BOTTOM) of the Z-order or after any non-topmost window. When a topmost window is made non-topmost, all of its owners and its owned windows are also made non-topmost windows.
A non-topmost window may own a topmost window, but not vice versa. Any window (for example, a dialog box) owned by a topmost window is itself made a topmost window, to ensure that all owned windows stay above their owner.
MoveWindow