(Full) movewindow and setwindowpos

Source: Internet
Author: User

 

You can only set the size and position of a movewindow. In addition to all functions of movewindow, setwindowpos can also set the window cascade relationship (for example, place the specified window in the top layer of all windows -- always on top can use this function, or place the specified window in the lower layer of another window, and so on ). There are no advantages and disadvantages, but the function size is different. You can use only setwindowpos instead of movewindow. However, you can use movewindow if you only need to set the window size or position.

Void Movewindow (Int x, int y, int nwidth, int nheight, bool brepaint = true );
Void 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 Program The part that must be re-painted in the cwnd and parent windows must be explicitly invalid or re-painted. 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.



BoolSetwindowpos (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.
The pwndinsertafter parameter 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: l 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. L wndtop: place the window on the top of the Z axis. L 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: l swp_drawframe draws a border around the window (defined when the window is created ). L 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. L swp_hidewindow: Hide 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. L 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. L swp_nomove: Keep the current position (ignore the X and Y parameters ). L swp_noownerzorder does not change the position of the owner window in the z-axis sequence. L swp_noredraw. 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. L swp_noreposition is the same as swp_noownerzorder. L swp_nosendchanging prevents the window from receiving wm_windowposchanging messages. L swp_nosize: Keep the current size (ignore the Cx and Cy parameters ). L swp_nozorder: Keep the current order (ignore pwndinsertafter ). L swp_showwindow: display window.

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.

Movewindow

Function: This function changes the position and size of a specified window. For the top-level window, the position and size are relative to the upper-left corner of the screen: For the child window, the position and size are relative to the upper-left corner coordinate of the parent window customer area.

Function prototype: bool movewindow (hwnd hwnd.int x.int y, int nwidth, int nheight, bool brepaint );

Parameters:

Hwnd: Window handle.

X: Specifies the left boundary of the new position of the window.

Y: Specifies the top boundary of the new position of the window.

Nwidth: Specify the new width of the window.

Nhaight: Specifies the new height of the window.

Brepaint: determines whether the window is refreshed. If this parameter is set to true, the window receives a wm_paint message. If this parameter is set to false, no refresh action is performed. It is applicable to the customer area, non-customer area (including the title bar and scroll bar), and the parent window area exposed by moving the Child Window. If the parameter is false, the application must explicitly invalidate the window or redraw the window and the parent window to be refreshed.

Return Value: If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To obtain more error information, call the getlasterror function.

NOTE: If brepaint is true, the system immediately sends the wm_paint message to the window process after the window is moved (that is, the movewindow function calls the updatewindow function ). If brepaint is set to false, the system places the wm_paint message in the message queue of the window. A message cycle sends a wm_paint message only when other messages in the message queue are sent.

Movewindow sends wm_wfnowposchanging, wm_windowposchanged, wm_move, wm_size, and wm_nccalcsize messages to the window,

Quick query: Windows NT: 3.1 or later: Windows: 95 or later; Windows CE: 1.0 or later: header file: winuser. h; library file: user32.lib.

 

I collect and learn from othersArticleI would like to express my gratitude to the authors or translators of these articles.

Change the widget size and position

You can use the functions movewindow () or setwindowpos () of the cwnd class to change the widget size and position.

Void movewindow (int x, int y, int nwidth, int nheight );
Void movewindow (lpcrect lprect );
The first method requires the new coordinates, width, and height of the control;
The second method provides the crect object of the storage location;
Example:
Cwnd * pwnd;
Pwnd = getdlgitem (idc_edit1); // gets the control pointer. idc_edit1 indicates the Control ID.
Pwnd-> movewindow (crect (100,100, 100); // an editing control with a width of 100 and a height of is displayed in the upper left corner of the window.

The setwindowpos () function is more flexible to use. It is mainly used when only the control position is changed but the size is not changed or only the size is changed but the position is not changed:
Bool setwindowpos (const cwnd * pwndinsertafter, int X, int y, int CX, int cy, uint nflags );
I will not use the first parameter. It is generally set to NULL;
Position of the X and Y controls; width and height of the Cx and Cy controls;
Common nflags values:
Swp_nozorder: Ignore the first parameter;
Swp_nomove: Ignore X and Y and keep the position unchanged;
Swp_nosize: Ignore CX and Cy and keep the size unchanged;
Example:
Cwnd * pwnd;
Pwnd = getdlgitem (idc_button1); // gets the control pointer. idc_button1 indicates the Control ID.
Pwnd-> setwindowpos (null, 50, 80, swp_nozorder | swp_nosize); // move the button to the window (50, 80)
Pwnd = getdlgitem (idc_edit1 );
Pwnd-> setwindowpos (null, 80, swp_nozorder | swp_nomove); // set the size of the Edit Control to (, 80), and the position remains unchanged
Pwnd = getdlgitem (idc_edit1 );
Pwnd-> setwindowpos (null, 80, swp_nozorder); // modify the widget size and position
The above method also applies to various windows

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/godyxfcode/archive/2007/04/20/1573295.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.