VC: movewindow and set?spos

Source: Internet
Author: User

Similarities and differences between movewindow and setwindospos

1. Prototype

Bool movewindow (

Hwnd,

Int X,

Int y,

Int nwidth, int nheight,

Bool brepaint );

 

Bool setwindowpos (

Hwnd,

Hwnd hwndinsertafter,

Int X, int y,

Int CX, int cy,

Uint uflags );

2. Same functions:

Both APIs can move the window position and change the window size. However, if the brepaint parameter in movewindow is false, the parent window will not be repainted;

While setwindowpos will be re-painted;

3. Differences

Movewindow can only move the window and change the size, but cannot change the Z sequence of the window;

Setwindowpos can change the Z-order window, window size, window location, set whether the window is activated, whether to display and hide, and recalculate the customer zone (powerful );

In addition, if you need to move multiple windows at a time, you can use begindeferwindowpos/deferwindowpos/enddeferwindowpos.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/zengwh/archive/2009/02/26/3939115.aspx

 

 

========================================================== ========================================================== ===

Another detailed article:

========================================================== ========================================================== ===

 

Method 1: Use the setwindowpos Function

Cwnd: setwindowposbool setwindowpos (const cwnd * pwndinsertafter, int X, int y, int CX, int cy, uint nflags );


If the function is successful, a non-zero value is returned; otherwise, 0 is returned.

Description

Call this member function to change the size, position, and Z-axis order of subwindows, pop-up windows, and top-layer windows. Windows are sorted by their Z axis order on the screen. At the top of the Z-axis order, the program is placed at the top of all other windows. All coordinates of the subwindow are customer coordinates (relative to the upper left corner of the parent window customer area ). The window can be moved to the top of the Z axis. You can set the pwndinsertafter parameter to & wndtopmost, and make sure that the swp_nozorder flag is not set, you can also set the z-axis order of the window so that it is located above all existing top-level windows. When a non-top-level window is set as a top-level window, its own window is also set as a top-level window. Its owner does not change. If the top-level window is located at the bottom of the Z axis (& wndbottom) or any non-top-level window, it is no longer a top-level window. When a top-level window is changed to a non-top-level window, all its owner and all its windows are changed to a non-top-level window. If neither the swp_noactive flag nor the swp_nozorder flag is specified (this means that the application requires that the window be activated at the same time and placed in the specified z-axis order ), then, the value specified in the pwndinsertafter parameter applies only in the following environments: l in the pwndinsertafter parameter, neither the & wndtopmost nor the & wndnotopmost parameter is specified.
This window is not an active window. The application cannot activate an inactive window without bringing it to the top of the Z axis order. The application can change the z-axis order of the active window without any restrictions. A non-top-level window may have a top-level window, but vice versa. Any window owned by a top-level window (such as a dialog box) changes itself to a top-level window to ensure that all owned windows are located above their owner. In Windows 3.1 or later versions, you can move windows to the top of the Z axis order and lock them there by setting their ws_ex_topmost style. This type of top-level window maintains its top-level position even if it is not active. For example, selecting the winhelp always on top command will change the Help window to the top level and remain visible after you return to the application. To create a top-level window, set the pwndinsertafter parameter to & wndtopmost when calling setwindowpos, or set the ws_ex_topmost style when creating the window. If the z-axis sequence contains any window with ws_ex_topmost style, the window moving with & wndtopmost will be placed at the top of all non-top-level windows, but located below any top-level window. When the application activates an inactive window that does not have the ws_ex_topmost style, the window is moved above all non-top-level windows, but below all top-level windows. If the pwndinsertafter parameter is set to & wndbottom when setwindowpos is called and cwnd is a top-level window, the window is out of the top-level State (ws_ex_bottom style is cleared ), and the system places the window at the bottom of the Z-axis order.

Parameter pwndinsertafter
Identifies the cwnd object located before the cwnd object in the z-axis order. This parameter can be a pointer to a cwnd object or a pointer to the following values:
Wndbottom places the window at the bottom of the Z-axis order. If this cwnd is a top-level window, the window will lose its top-level state. The system places this window at the bottom of all other windows.
Wndtop places the window at the top of the Z axis order.
Wndtopmost places the window above all non-top-level windows. This window will keep its top-level position even if it loses its activity status.
Wndnotopmost relocates the window to the top of all non-top-level windows (this means that it is under all top-level windows ). This flag does not work for non-top-level windows. For more information about this function and the usage rules of these parameters, see the description section.

X specifies the new position on the left of the window.
Y specifies the new position at the top of the window.
CX specifies the new window width.
Cy specifies the new height of the window.

Nflags specifies the size and position options. This parameter can be a combination of the following values:
Swp_drawframe draws a border around the window (defined when the window is created ).
Swp_framechanged sends a wm_nccalcsize message to the window, even if the window size does not change. If this flag is not specified, the wm_nccalcsize message is sent only when the window size changes.
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 the top-level or non-top-level window group (dependent on the settings of the pwndinsertafter parameter.
Swp_nocopybits discards the content in this customer zone. If this parameter is not specified, the valid content of the customer zone will be saved and copied back to the customer zone after the size or position of the window changes.
Swp_nomove retains the current position (ignore the X and Y parameters ).
Swp_noownerzorder does not change the position of the owner window in the z-axis sequence.
Swp_noredraw does not reproduce the changes. If this flag is set, no changes of any type will occur. This applies to the customer area, non-customer area (including the title and scroll bar), and any part of the parent window overwritten by the moving window. When this flag is set, the application must explicitly invalidate or redraw any part of the window to be repainted and any part of the parent window.
Swp_noreposition is the same as swp_noownerzorder.
Swp_nosendchanging prevents the window from receiving wm_windowposchanging messages.
Swp_nosize: Keep the current size (ignore the Cx and Cy parameters ).
Swp_nozorder maintains the current order (ignore pwndinsertafter ).
Swp_showwindow: display window.

Method 2: Use the movewindow Function

Void cwnd: movewindow (int x, int y, int nwidth, int nheight, bool brepaint = true );
Void cwnd: movewindow (lpcrect lprect, bool brepaint = true );
Parameters
X specifies the new position on the left of cwnd.
Y specifies the new position on the top of cwnd.
Nwidth specifies the new width of cwnd.
Nheight specifies the new height of cwnd.
Brepaint specifies whether to re-draw cwnd. If it is true, cwnd receives a wm_paint message in the onpaint message processing function as usual. If this parameter is set to false, no type of re-painting will be performed. This applies to the customer area, non-customer area (including title bar and scroll bar), and any part of the parent window exposed by cwnd movement. When this parameter is set to false, the application must explicitly invalidate or redraw the required part of the cwnd and parent windows.

The lprectcrect object or rect structure, specifying the new size and position. This function changes the position and size of the window. For the top-level cwnd object, the X and Y parameters are relative to the upper left corner of the screen. For sub-objects, they are relative to the upper left corner of the parent window customer area.
The movewindow function sends a wm_getminmaxinfo message. When processing this message, cwnd gets an opportunity to change the maximum and minimum window defaults. If the parameter passed to the movewindow member function exceeds these values, the minimum or maximum value can be used in the wm_getminmaxinfo processing function.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/wirror800/archive/2009/03/16/3994608.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.