Preface: The first method can not change the position of two picture control at the same time, do not know why;
The function MoveWindow () or SetWindowPos () of the CWnd class can change the size and position of the control.
void MoveWindow (int x,int y,int nwidth,int nheight);
void MoveWindow (Lpcrect lpRect);
The first usage should give the new coordinates and width and height of the control.
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 a height of 100 in the upper-left corner of the window
The
SetWindowPos () function is more flexible to use in situations where only the position of the control is modified or the size is unchanged or only the size is changed:
BOOL setwindowpos (const cwnd* pWndInsertAfter, int x,int y,int cx,int cy,uint nflags);
The first parameter I do not use, generally set to null;
X, y control position, CX, CY Control width and height,
nflags common value:
Swp_nozorder: Ignore first argument,
Swp_nomove: Ignore x, y, maintain position;
Swp_ Nosize: Ignore CX, CY, maintain size unchanged;
Example:
CWnd *pwnd;
PWnd = GetDlgItem (idc_button1);//Get control pointer, idc_button1 as control ID number
pwnd- >setwindowpos (Null,50,80,0,0,swp_nozorder | Swp_nosize); Move the button to the window at (50,80)
PWnd = GetDlgItem (idc_edit1);
Pwnd->setwindowpos (Null,0,0,100,80,swp_nozorder | Swp_nomove); Set the size of the edit control to (100,80), the position is unchanged
PWnd = GetDlgItem (idc_edit1);
Pwnd->setwindowpos (Null,0,0,100,80,swp_nozorder ); //the size and position of the edit control are changed
the above methods also apply to various windows.