I have an MFC doc/view app, MDI. A document has 7 views (based on CScrollView
), and I want to have the ability to limit the size of each view window.
Users can change the size of a view by dragging on the edge, or using the maximize / restore button in the title bar of each view. The program changes the sizes of the views according to the data being displayed for a document.
It seems what I should be using is the WM_GETMINMAXINFO
message. But, when I add a handler and ON_WM_GETMINMAXINFO()
to my message map, I do not get any notifications when the user changes the size of a view. I've tried adding the handler to my main frame window (CMainFrame
), to the view window, and to CChildFrame
. None of these give notifications when the view window size changes, although I do get notifications when the main frame window size is changed.
What is the right way to limit the size of the view windows?
Windows 11, Visual Studio 2022, C++
Edit: This is the code I'm using to create the additional views. It is probably why I'm not seeing the notifications, but I don't see how to fix it.
// This adds a window to the main frame and creates a view class instance
void CAnalyzeDoc::CreateAdditionalView(ViewType viewType)
{
CDocTemplate *pTemplate = GetDocTemplate();
CFrameWnd *pFrame = pTemplate->CreateNewFrame(this, NULL);
CAnalyzeView *pAnalyzeView = NULL;
pAnalyzeView = (CAnalyzeView *)pFrame->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
pAnalyzeView->viewType = viewType;
CSize sizeTotal; // size of the contents to be shown in this CScrollView window (may be < window size, then scrollbars will appear)
sizeTotal.cx = 1;
sizeTotal.cy = 1;
pAnalyzeView->SetScrollSizes(MM_TEXT, sizeTotal);
pTemplate->InitialUpdateFrame(pFrame, this);
}
Could not reproduce.
This works for having a minimal size of 200x200 and a maximum size of 400x400 for your child frame windows:
Message map:
The same thing for the
CMainFrame
class also works as expected:Message map:
Try this yourself with a wizard created MFC MDI application and check what is different in your code.