VC + + Follow parent window resize control

Source: Internet
Author: User

VC + + Adjust the size of the control based on the dialog box size
1. Add the member variable CRect m_rect in the dialog class to save the size before the size of the dialog box changes;
2. In the OnInitDialog () function of the dialog box, get the size of the dialog box when it was created: GetClientRect (&m_rect);

3. Add the following code to the Wm_size response function OnSize ():


1:private:
CRect M_rect;

2:getclientrect (&m_rect);


3:

void Cbuttondlg::modify (cwnd* pwnd,int cx,int cy)
{
if (pWnd)
{
CRect rect; Gets the size of the control before it changes
Pwnd->getwindowrect (&rect);
ScreenToClient (&rect); Convert the control size to the area coordinates in the dialog box

Cx/m_rect. Width () is the ratio of the dialog box to the horizontal change
Rect.left = Rect.left * Cx/m_rect. Width ();
Rect.right = Rect.right * Cx/m_rect. Width ();
Rect.top = Rect.top * Cy/m_rect. Height ();
Rect.bottom = Rect.bottom * Cy/m_rect. Height ();
Pwnd->movewindow (rect);
}
}

void Cbuttondlg::onsize (UINT nType, int cx, int cy)
{
Cdialog::onsize (NType, CX, CY);

cwnd* PWnd1 = GetDlgItem (Idc_button1);
cwnd* PWnd2 = GetDlgItem (Idc_button2);
cwnd* PWnd3 = GetDlgItem (Idc_button3);
cwnd* PWnd4 = GetDlgItem (Idc_button4);
cwnd* PWnd5 = GetDlgItem (IDC_BUTTON5);

Modify (Pwnd1,cx,cy);
Modify (Pwnd2,cx,cy);
Modify (Pwnd3,cx,cy);
Modify (Pwnd4,cx,cy);
Modify (Pwnd5,cx,cy);

GetClientRect (&m_rect);//Gets the size of the new dialog box
}



VC + + Follow parent window resize control

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.