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 |