VC ++: SetWindowPos

The SetWindowPos (
the hWnd: the HWND; window handle {}
hWndInsertAfter: the HWND; the Z order of windows {}
X-, the Y: Integer; {location}
CX, CY: Integer; {size}
the uFlags: Option} {UINT
): 

Function: This function changes a child window, the size of top-level window pop-up window type, position and Z order. Sub-window, a pop-up window and the top layer according to the ranking order they appear on the screen, the highest level of the top-level window is provided, and is disposed to the first window in the Z order.
Function prototype: BOOL SetWindowPos (HWN hWnd, HWND hWndlnsertAfter, int X, int Y, int cx, int cy, UNIT.Flags);
parameters:
the hWnd: window handle.
hWndlnsertAfter: window handle is located in front of a window set in the order of z. The parameter must be a window handle, or one of the following:
HWND_BOTTOM: window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses top position, and the other is set at the bottom of the window.
HWND_DOTTOPMOST: non-window above all top-level windows (i.e., after all top-level windows). If the window has a non-top-level window, the flag has no effect.
HWND_TOP: The window is placed on top of the Z order.
HWND_TOPMOST: The window above all non-top-level windows. Even if the window is not the active window will remain in the top position.

See use this parameter, see the Description section.
x: Customer-specified coordinate position of the left edge of the new window.
Y: Customer-specified coordinates of the new location of the top of the window border.
cx: Specifies the new width of the window in pixels.
cy: new height in pixels of the specified window.


// uFlags optional parameter values:
SWP_NOSIZE =. 1; ignore {cx, cy, the size of the holding}
SWP_NOMOVE = 2; ignore {X, Y, without changing the position of}
the SWP_NOZORDER =. 4; {ignore hWndInsertAfter, maintaining the order of Z}
SWP_NOREDRAW. 8 = ; {not redraw}
SWP_NOACTIVATE = $ 10; {do not activate}
SWP_FRAMECHANGED = $ 20 is; {forced transmission WM_NCCALCSIZE message, generally only sends this message when the size is changed}
SWP_SHOWWINDOW = $ 40; {display window}
SWP_HIDEWINDOW = $ 80; {hidden window }
SWP_NOCOPYBITS = $ 100; {discarding the client area}
SWP_NOOWNERZORDER = $ 200 is; {ignore hWndInsertAfter, without changing the Z sequence owner}
SWP_NOSENDCHANGING = $ 400; {not issue WM_WINDOWPOSCHANGING message}
SWP_DRAWFRAME = SWP_FRAMECHANGED; {Videos border}
SWP_NOREPOSITION = SWP_NOOWNERZORDER; {}
SWP_DEFERERASE = $ 2000; {prevent WM_SYNCPAINT message}
SWP_ASYNCWINDOWPOS = $ 4000; {if the calling process does not have a window, the system will be sent to the thread that owns the window needs}

Return Value: If the function succeeds, the return value is zero; if the function fails, the return value is zero. To get extended error information, call GetLastError.
NOTE: If SWP_SHOWWINDOW and SWP_HIDEWINDOW flag is set, the window can not be moved and resized. If you use SetWindowLoog changed some of the data window, you must call SetWindowPos function to make real change. Use the following combinations of flags: SWP_NOMOVEISWP_NOSIZEISWP_FRAMECHANGED.
There are two ways to window the topmost window: one is to set the parameter hWndlnsertAfter HWND_TOPMOST SWP_NOZORDER and ensure that no flag is set; the other is provided in the Z position of the window in order to make it present in the top of other windows . When a window is set to topmost window

Comment:

If the specified SWP_SHOWWINDOW or SWP_HIDEWINDOW, the window can not be moved or resized. 
All coordinates are the coordinates of the child window client area (relative to the upper left corner of the client area of the parent window). 
A window can become a Topmost window set by the window by setting its parameters to HWND_TOPMOST hWndInsertAfter and ensure SWP_NOZORDER flag is not set, or position in the Z-axis direction, so that it Topmost on any existing window when a window is set to a non-Topmost TopMost, it has also become the window, but its owner are not changed.

SWP_NOACTIVATE If the flag is not specified and SWP_NOZORDER (refer to when the application window is active at the same time requires changes its position in the Z-axis direction), the hWndInsertAfter only in the following situations: 
1.HWND_TOPMOST and HWND_NOTOPMOST signs are hWndInsertAfter not specified. 
2.hWnd handle the specified window is not the active window.

If an application is not adjusted to a non-active window to the top of the Z-axis direction, you can not activate the inactive window. An application can change the position of the active window in the Z-axis direction is not limited, it is possible to activate a window and move it to the top of the topmost or non-topmost window. 
If a topmost window to be relocated to the bottom (HWND_BOTTOM) Z-axis direction, or behind any non topmost window, then it is not a topmost window when a window becomes non Topmost topmost window, its owner and its the window has also become a non-topmost window.

A non-Topmost Topmost window can have a window, but not vice versa any window. (For example: a dialog box) owned by a Topmost window, but it also makes itself as a Topmost window, make sure all windows are owned by them in above owners.
If an application is not in the foreground, but to become the foreground program, it should call SetForegroundWindow function.

 

Personal summary the following points should be noted:

Source: http://www.cppblog.com/zaccheo/archive/2012/08/24/188156.aspx

1. Set the window when there is ZOrder SWP_SHOWWINDOW or SWP_HIDEWINDOW SetWindowPos nFlags parameter settings of the parameters and settings size hWndInsertAfter position x, y, cx, cy invalid. This specifically stated in the msdn

2. When set to achieve top window is actually SetWindowPos increase WS_EX_TOPMOST extended style through to the window. The WS_EX_TOPMOST the extended style is only set to the top of the window (top level window). This means that those sub-window (with a ws_child style) window to call the following code is invalid, but the tragedy is that the return value of this call is still true.

 

Guess you like

Origin blog.csdn.net/smartgps2008/article/details/90723201