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.
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 }}