SetWindowPos

Syntax

void SetWindowPos(hWnd,hWndInsertAfter,X,Y,cx,cy,wFlags)

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 window above all other windows receives the highest rank, and it is the first window in the list. This ordering is recorded in a window list.

Parameter Type/Description  

hWnd HWND Identifies the window that will be positioned.  
hWndInsertAfter HWND Identifies a window in the window-manager's list that will precede the window identified by the hWnd parameter. If the window identified by the hWnd parameter has the WS_ES_TOPMOST style and hWndInsertAfter is –1, the window is placed at the top of the hierarchy of topmost windows and remains above all non-topmost windows, even when inactive. If the window has the WS_ES_TOPMOST style and hWndInsertAfter is 1, the window is no longer treated as a topmost window and is placed below all other windows.  
X int Specifies the x-coordinate of the window's upper-left corner.  
Y int Specifies the y-coordinate of the window's upper-left corner.  
cx int Specifies the new window's width.  
cy int Specifies the new window's height.  
wFlags WORD Specifies one of eight possible 16-bit values that affect the sizing and positioning of the window. It must be one of the following values:  
  Value Meaning
  SWP_DRAWFRAME Draws a frame (defined in the window's class description) around the window.
  SWP_HIDEWINDOW Hides the window.
  SWP_NOACTIVATE Does not activate the window.
Parameter Type/Description  

  Value Meaning
  SWP_NOMOVE Retains current position (ignores the x and y parameters).
  SWP_NOSIZE Retains current size (ignores the cx and cy parameters).
  SWP_NOREDRAW Does not redraw changes.
  SWP_NOZORDER Retains current ordering (ignores the hWndInsertAfter parameter).
  SWP_SHOWWINDOW Displays the window.

Return Value

None.

Comments

If the SWP_NOZORDER flag is not specified, Windows places the window identified by the hWnd parameter in the position following the window identified by the hWndInsertAfter parameter. If hWndInsertAfter is NULL, Windows places the window identified by hWnd at the top of the list. If hWndInsertAfter is set to 1, Windows places the window identified by hWnd at the bottom of the list.

If the SWP_SHOWWINDOW or the SWP_HIDEWINDOW flags are set, scrolling and moving cannot be done simultaneously.

All coordinates for child windows are relative to the upper-left corner of the parent window's client area.