How to limit view window size in MFC doc/view MDI?

51 views Asked by At

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);
}
1

There are 1 answers

2
Jabberwocky On

Could not reproduce.

This works for having a minimal size of 200x200 and a maximum size of 400x400 for your child frame windows:

void CChildFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
    lpMMI->ptMaxTrackSize.x = 400;
    lpMMI->ptMaxTrackSize.y = 400;
    lpMMI->ptMinTrackSize.x = 200;
    lpMMI->ptMinTrackSize.y = 200;
    CMDIChildWnd::OnGetMinMaxInfo(lpMMI);
}

Message map:

BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
    ...
    ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()

The same thing for the CMainFrame class also works as expected:

void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
    lpMMI->ptMaxTrackSize.x = 1000;
    lpMMI->ptMaxTrackSize.y = 800;
    lpMMI->ptMinTrackSize.x = 400;
    lpMMI->ptMinTrackSize.y = 400;
    CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
}

Message map:

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
    ON_WM_CREATE()
    ...
    ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()

Try this yourself with a wizard created MFC MDI application and check what is different in your code.