You can adapt & improve the old MS KB Q112639 (C/Win32, 1992)
I re-compiled it in VS 2020 : SclblDlg.zip
How can we increase or decrease the size of dialog box so that it can also change the size of all the button and menu also in MFC?
void CMFCApplication6Dlg::OnFontIncreasefont()
{
/*LPCTSTR text = _T("Hello World");
SetDlgItemTextW(IDD_MFCAPPLICATION6_DIALOG,text);*/
Correct rect;
GetClientRect(&rect);
x = rect.Height();
int y = rect.Width();
cout << x << endl;
cout << y << endl;
SetWindowPos(NULL, 200, 300, x + 150, y + 10, SWP_NOMOVE);
CFont font;
font.CreateFont(
fon + 5, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("Arial")); // lpszFacename
fon = fon + 5;
GetDlgItem(IDC_STATIC1)->SetFont(&font);
GetDlgItem(IDC_STATIC2)->SetFont(&font);
GetDlgItem(IDOK)->SetFont(&font);
GetDlgItem(IDC_EDIT2)->SetFont(&font);
}
4 answers
Sort by: Most helpful
-
Castorix31 85,796 Reputation points
2022-12-27T08:56:59.143+00:00 -
Minxin Yu 11,996 Reputation points Microsoft Vendor
2022-12-27T08:48:50.253+00:00 Hi, @Aman Anand
Welcome to Microsoft Q&A!You can use WM_SIZE message and CWnd::movewindow.
void CMFCApplication6Dlg::OnSize(UINT nType, int cx, int cy) { CDialogEx::OnSize(nType, cx, cy); CWnd* pwnd = GetDlgItem(IDC_XXX); if (pwnd->GetSafeHwnd()) { pwnd->MoveWindow(...); } // TODO: Add your message handler code here }
Best regards,
Minxin Yu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. -
Minxin Yu 11,996 Reputation points Microsoft Vendor
2022-12-28T09:45:19.22+00:00 Below is a simple snippet to modified controls' size. You need to add additional adjustments for special controls.
variables in MFC dlg.h
CRect m_rect;
std::vector<CRect> storeRect;OnInitDialog() { // TODO: Add extra initialization here for (CWnd* pwnd = GetWindow(GW_CHILD); pwnd != NULL; pwnd = pwnd->GetWindow(GW_HWNDNEXT)) { CRect rect; ::GetWindowRect(pwnd->GetSafeHwnd(), &rect); ScreenToClient(&rect); storeRect.push_back(rect); } ::GetClientRect(m_hWnd, &m_rect); ScreenToClient(&m_rect); } void CMFCApplication6Dlg::OnSize(UINT nType, int cx, int cy) { CDialogEx::OnSize(nType, cx, cy); if (m_rect.Width() != 0) { int count = 0; for (CWnd *pwnd = GetWindow(GW_CHILD); pwnd != NULL; pwnd = pwnd->GetWindow(GW_HWNDNEXT)) { CRect temp; temp.CopyRect(&storeRect[count]); float width = (float)cx / m_rect.Width(); float hight = (float)cy / m_rect.Height(); temp.left *= width; temp.right *= width; temp.top *= hight; temp.bottom *= hight; if (pwnd->GetSafeHwnd()) { pwnd->MoveWindow(temp); } count++; } } }
-
Aman Anand 1 Reputation point
2023-01-09T07:28:58.183+00:00 if i am trying to use by my code, it's not increasing respective of dialog and button .