Adjusting frame size in an SDI

How can I best adjust an SDI frame size such that either:

   1. Only toolbars and dialog bars are displayed,
      even if the user decides to adjust the size
      of the frame.
   2. Only a CFormView is displayed (not my preferred
      choice due to the quality of display, particularly
      in terms of 3D and extra space between the
      dialog and the frame.

I don't want to use a dialog based application. Possibly one route is to get rid of the document class, since as I indicated, I really want to get rid of the document view.

Thanks for your input.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You must handle WM_GETMINMAXINFO message in your frame class and set maximum and minimum sizes.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RJVAuthor Commented:
Please be a bit more specific. Namely, how to change the size of the frame to display only the toolbars and dialog bar or CFormView bar?

I ran some tests here and found that WM_GETMINMAXINFO gets called before CMainFrame::OnCreate(). Thus the frame hasn't even been created at that point, nor have any toolbars or the dialog bar. Thus, I can't have it resize at that point, for example. Moreover, the size information is a bit confusing.


Ok, WM_GETMINMAXINFO is sent to parent frame window when ANY operation touching upon changing size of the window is about to be processed. For instance when you minimize/maximize/restore or resize window. This allows you to prevent changing of window size. So you want to show only toolbar and dialog bar, i.e. you want client area of your frame(view) to be zero sized. So
you should do the following.

void CMainFrame::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
CFrameWnd::OnGetMinMaxInfo( lpMMI );

CRect rc(0,0,0,0);
//calculate window rectangle based on zero sized client area
// restict window both track and max size
ptMaxSize.x = ptMaxTrackSize.x = rc.Width();
ptMaxSize.y = ptMaxTrackSize.y = rc.Height();
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

RJVAuthor Commented:
Galkin, you've gotta try that one yourself. I guarantee the outcome to be a good laugh! The resizing so effective it'll be somewhat of a challenge to find the application.

This is most probably thanks to the moment the message is activated.


I am sorry I missed two important things.
First CalcWindowRect doen's add menu to adjusted recangle, and second you should check whether your bars window exist.

This is improved code for window which has only one tool bar but it can be easily extended for several control bars

1.Add WM_GETMINMAXINFO handler to your parent frame and implement the following code(m_wndToolBar is member variable of type CToolBar, generated by AppWizard)
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
// TODO: Add your message handler code here and/or call default

      CRect rc;

      ::AdjustWindowRectEx(&rc, GetStyle(), TRUE, NULL);
      // restict window both track and max size
      lpMMI->ptMaxSize.x = lpMMI->ptMinTrackSize.x =
lpMMI->ptMaxTrackSize.x = rc.Width();
      lpMMI->ptMaxSize.y = lpMMI->ptMinTrackSize.y =
lpMMI->ptMaxTrackSize.y = rc.Height();

2.After toolbar window is created in CMainFrame::OnCreate handler call ShowWindow(SW_SHOWMAXIMIZED);
RJVAuthor Commented:
Super! Since Murphy is having fun with coding (coding is a favorite of his anyway), there are two areas to be repaired with this:

  1. A lot of screen flicker upon starting up. It is
     evident that the screen gets maximized and then

  2. If you've tried this you'll have to fix it to
     include the status bar, which I did by adding
     in its CRect.height. The problem is if you try to
     increase the size of the screen you wind up with
     a blank line between the dialog bar and the status

BTW, don't forget to tell Murphy to go packing first!


I just showed you the idea. Of cause to implement this as it must be implemented you should not rely upon AdjustWindowRectEx but to calculate the frame window recatngle based on zero client rectangle and all control bars you have. Then you should not call ShowWindow which of cause causes flickeing since window is already displayed. You should create your parent frame invisible and show it only when all your control bars are created and set it window position using SetWindowPos after calculating the size using the same method used in calculating window rectangle in OnGetMinMaxInfo.
RJVAuthor Commented:
I was wondering if the solution you'd suggest would go through setting the frame to invisible. I'll see why moving things later cause the problem too.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.