[MFC] Dynamically Change dialog box control position dimensions

Source: Internet
Author: User


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.

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.