You can change the size and position of a control by using the function MoveWindow () or SetWindowPos () of the CWnd class.
void MoveWindow (int x,int y,int nwidth,int nheight);
void MoveWindow (Lpcrect lprect);
The first usage needs to give the control new coordinates and the width, the height;
The second usage gives the CRect object of the storage location;
Cases:
CWnd *pwnd;
pwnd = GetDlgItem (IDC_EDIT1); Gets the control pointer, idc_edit1 the control ID number
Pwnd->movewindow (CRect (0,0,100,100));//Display an edit control with a width of 100 and 100 in the upper-left corner of the window
The SetWindowPos () function is more flexible in that it is used to modify only the position of the control but not the size or the size of the position:
BOOL SetWindowPos (const cwnd* pwndinsertafter,int x,int y,int cx,int);
The first parameter I do not use, generally set to null;
x, y control position; CX, CY control width and height;
Nflags commonly used values:
Swp_nozorder: ignores the first parameter;
Swp_nomove: Ignore x, Y, maintain position unchanged;
Swp_nosize: Ignore CX, CY, maintain the same size;
Cases:
CWnd *pwnd;
pwnd = GetDlgItem (Idc_button1); Gets the control pointer, idc_button1 the control ID number
Pwnd->setwindowpos (Null,50,80,0,0,swp_nozorder | Swp_nosize); Move the button to the window (50,80) at
pwnd = GetDlgItem (idc_edit1);
Pwnd->setwindowpos (Null,0,0,100,80,swp_nozorder | Swp_nomove); The size of the edit control is set to (100,80) and the position is constant
pwnd = GetDlgItem (idc_edit1);
Pwnd->setwindowpos (Null,0,0,100,80,swp_nozorder); Edit controls vary in size and position
The above methods are also applicable to various windows.
The above mentioned is the entire content of this article, I hope you can enjoy.