In 1997, I have used C++ to create an MDI MFC program.
I have created a Class named XFormFiew that extends MFC CFormView class.
In OnInitialUpdate()
event method, I have written some codes to modify automatically the zooming of the view.
In the past, the majority of screen resolution are 800x600, but now the resolution is higher. In zooming automatically in XFormView
, I avoid to made some modifications in all my views.
The zooming code modify Left and Bottom but also Width and Height of each CWnd
contained in active CFormView
The code is the following
void XFormView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
pLogFont = new LOGFONT;
CFont* pDialogFont = GetFont();
pDialogFont->GetObject(sizeof(LOGFONT),pLogFont);
pLogFont->lfHeight = MulDiv(pLogFont->lfHeight, Config.GetDstH(), Config.GetSrcH());
pLogFont->lfWeight = FW_NORMAL;
pFont = new CFont;
pFont->CreateFontIndirect(pLogFont);
SetFont(pFont);
CWnd* pWnd;
pWnd = GetWindow(GW_CHILD);
while (pWnd != NULL)
{
ZoomWnd(pWnd);
pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}
// TRY to modify WIDTH and HEIGTH of CFormView
ZoomWnd(this);
}
void XFormView::ZoomWnd(CWnd* pWnd)
{
CRect rect;
pWnd->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.left = (int)((long)rect.left * Config.GetDstH() / Config.GetSrcH());
rect.top = (int)((long)rect.top * Config.GetDstV() / Config.GetSrcV());
rect.right = (int)((long)rect.right * Config.GetDstH() / Config.GetSrcH());
rect.bottom = (int)((long)rect.bottom * Config.GetDstV() / Config.GetSrcV());
pWnd->MoveWindow(&rect);
pWnd->SetFont(pFont);
}
The code work well but for some views, the vertical and horizontal scrollbar are missing.
The Window is always loaded MAXIMIZED. If I unmaximize Window, the scrollbars are always missing.
If I reduce WIDTH or HEIGHT the scrollbar is displayed WHEN width or height reaches what has been defined in RC Resource file.
Example:
IDD_OVFORM DIALOGEX 0, 0, 370, 297
where 370 is the width of Form and 297 is height.
If I reduce Child Window width, nothing happens until width is reduced to 370. At this moment an horizontal scrollbar is automatically displayed.
My problem is how to change dynamically (not in RC file) the width and height of IDD_OVFORM to correspond to zoom level so that horizontal and vertical scrollbar are displayed correctly ?
I have already try to change these properties in OnInitialUpdate() method but nothing is working.
If I change Width and Height in RC Resource FILE, the zoom work correctly for a specific zoom level (but not for all zoom level).
On Internet, I find a some solutions about removing Scrollbars but not about zooming and Scrollbars missing using MDI MFC Form.
Is there somebody that has already found a solution to this problem ?
2019-02-12: thanks to Barmak Shemirani for his solution (OPTION 3) that works perfectly.