The MFC allows the control to change with the window size. The MFC control window size

Source: Internet
Author: User

The MFC allows the control to change with the window size. The MFC control window size

Reprinted from http://blog.csdn.net/chw1989/article/details/7488711

Both the size and position are changed (it is feasible for the test)

1. First, add the CRect m_rect for the form class. This member variable is used to record the current size of the form.

2. In the Class Wizard (Ctrl + W), add the response function OnSize () for the message WM_SIZE to the form ();

Note that if (nType = 1) return; this sentence must be added; otherwise, an error occurs when the restoration is minimized.

  1. Void CPaperManagementDlg: OnSize (UINT nType, int cx, int cy) {CDialog: OnSize (nType, cx, cy); if (nType = 1) return; // do nothing if minimized // TODO: Add your message handler code here CWnd * pWnd; pWnd = GetDlgItem (IDC_STATIC); ChangeSize (pWnd, cx, cy ); pWnd = GetDlgItem (IDC_FILE_TREE); ChangeSize (pWnd, cx, cy); pWnd = GetDlgItem (IDC_EDIT_NAME); ChangeSize (pWnd, cx, cy); pWnd = GetDlgItem (IDC_EDIT_REFERENCE ); changeSize (pWnd, cx, cy); pWnd = GetDlgItem (IDC_EDIT_SUMMARY); ChangeSize (pWnd, cx, cy); pWnd = GetDlgItem (IDC_EDIT_REMARK); ChangeSize (pWnd, cx, cy); pWnd = GetDlgItem (IDC_BUTTON_UPDATE); ChangeSize (pWnd, cx, cy); pWnd = GetDlgItem (IDC_BUTTON_SAVE); ChangeSize (pWnd, cx, cy ); pWnd = GetDlgItem (IDC_STATIC_1); ChangeSize (pWnd, cx, cy); pWnd = GetDlgItem (IDC_STATIC_2); ChangeSize (pWnd, cx, cy); pWnd = GetDlgItem (IDC_STATIC_3 ); changeSize (pWnd, cx, cy); pWnd = GetDlgItem (IDC_STATIC_4); ChangeSize (pWnd, cx, cy); GetClientRect (& m_rect ); // set the size of the changed dialog box to the old size}

    Changesize is a self-added function.

Void CPaperManagementDlg: ChangeSize (CWnd * pWnd, int cx, int cy) {if (pWnd) // determines whether it is null, because this function is called when the dialog box is created, at that time, the control has not created {CRect rect; // obtain the size of the control before changes pWnd-> GetWindowRect (& rect); ScreenToClient (& rect ); // convert the control size to the region coordinate in the dialog box // cx/m_rect.Width () is the ratio of horizontal variation in the dialog box rect. left = rect. left * cx/m_rect.Width (); // adjust the widget size 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); // set the control size }}

  

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.