On MFC changing control size and position _c language

Source: Internet
Author: User

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.

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.