MFC General: How to prevent a resizable window to be smaller than...?

Q: How to prevent a resizable window to be smaller than...?

A: Handle 'WM_GETMINMAXINFO' message:

void CWndDerived::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// set the minimum tracking width
// and the minimum tracking height of the window
lpMMI->ptMinTrackSize.x = 200;
lpMMI->ptMinTrackSize.y = 150;
}

 

Q: My resizable window is a dialog and I do not see 'WM_GETMINMAXINFO' in the messages list of ClassWizard. What can I do?
A: Because 'WM_GETMINMAXINFO' is by default filtered by class wizard for a 'CDialog' derived class, you can add the 'ON_WM_GETMINMAXINFO()' macro and the corresponding handler function by hand, or:

  • in MFC ClassWizard select 'Class Info' tab and choose 'Window' from 'Message filter' combo.
  • go back to 'Message Maps', select your CDialog-derived class in 'Object IDs' list and then 'WM_GETMINMAXINFO' from the messages list.

Q: My application is SDI/MDI. The required minimum size is given by the view. I handled 'WM_GETMINMAXINFO' in my CView-derived class but does not work. What I'm doing wrong?

A: A view is not responsible for sizing. Handle 'WM_GETMINMAXINFO' in the corresponing frame window:

void CChildFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// the minimum client rectangle (in that is lying the view window)
CRect rc(0, 0, 200, 150);
// compute the required size of the frame window rectangle
// based on the desired client-rectangle size
CalcWindowRect(rc);

lpMMI->ptMinTrackSize.x = rc.Width();
lpMMI->ptMinTrackSize.y = rc.Height();
}

Q: My application is SDI/MDI. I don't want to be resizable at all.

A: Set also the maximum track size:

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

An alternative solution is to simply remove 'WS_THICKFRAME' style in 'PreCreateWindow()':

BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if(!CMDIChildWnd::PreCreateWindow(cs))
return FALSE;
cs.style &= ~WS_THICKFRAME;
return TRUE;
}

Note: Most of the material in this article is taken from codeguru.com


Recommended Reading :

Comments

Resizing Dialog

Hi,
I m developin my project so tat my main dialog must fit into
screens based upon various resolutions..
Is there any way to fix the width & height of the dialog
thru coding???

Bavi





Cheap Gas - Loans - United Specialties - Credit Card Consolidation