[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

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.
RJV
0
RJV
Asked:
RJV
  • 4
  • 4
1 Solution
 
galkinCommented:
You must handle WM_GETMINMAXINFO message in your frame class and set maximum and minimum sizes.
0
 
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.

RJV

0
 
galkinCommented:
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
CalcWindowRect(&rc);
// restict window both track and max size
ptMaxSize.x = ptMaxTrackSize.x = rc.Width();
ptMaxSize.y = ptMaxTrackSize.y = rc.Height();
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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.

RJV

0
 
galkinCommented:
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

      if(m_wndToolBar.GetSafeHwnd())
      {
      CRect rc;
      m_wndToolBar.GetWindowRect(&rc);
      ScreenToClient(&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();
      }
      
      CFrameWnd::OnGetMinMaxInfo(lpMMI);
}

2.After toolbar window is created in CMainFrame::OnCreate handler call ShowWindow(SW_SHOWMAXIMIZED);
0
 
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
     resized.

  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
     bar.

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

RJV

0
 
galkinCommented:
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.
0
 
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.

RJV

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now