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