Link to home
Start Free TrialLog in
Avatar of kaplan1
kaplan1

asked on

Resize viewable area in FormView

Hello,

I have a form/view MFC application.  I need to be
able to dynamically shrink the window.  I am able to
resize the window, however the window ends up
automatically getting scrollbars added.  It appears that
the actual viewable area (which is now scrollable) has
not changed.  How can I shrink the viewable area also so
that the scrollbars do not appear.

I can't simply make the window not have scrollbars because
I want the scrollbars to appear if the user manually
changes the size of the window.

Thanks,
Mark
Avatar of milenvk
milenvk

CFormView determines the viewable area by the dialog template. So to shrink the viewable area try to shrink the dialog in the dialog resource editor as much as possible. Even if you have a small control at the upper left corner of the dialog, but the dialog is say bigger than the screen, you'll always get scrollbars.

If you want to disable the scrollbars you can handle the WM_SIZE message in your CFormView derivative class and delete the call to CFormView::OnSize() from the default handler. But, as you said your users need the scrollbars - so consider the first solution.

Avatar of kaplan1

ASKER

1. I cannot use option 1, because I must make the decision whether or not to
shrink the viewable area at runtime.  Therefore I cannot make the change in
the resource editor.

2. I cannot use option 2, because I must allow the user to manually shrink
the application to any size (which would then require scrollbars).
Ok - here's something that'll work for sure for you:

Use CFormView::SetScrollSizes() to set the viewable area. You can always use it to change the area at which the view reacts with showing or hiding the scrollbars. This is a member function of CScrollView which is the class from which CFormView inherits. CFormView calls SetScrollSizes to set the viewable area in CFormView::Create() only - so you can change that at any moment after the call to CFormView::Create(), i.e. you can freely change the viewable area after the creation of the view using SetScrollSizes().
Avatar of kaplan1

ASKER

Thank you very much for the help, and I think we almost have it solved.  It tried
to use SetScrollSizes(), and it does not exactly work how I expected.  For a test
I simply call the following function, which when run, surprising adds scrollbars.

int CMoveView::ScrollTest()
{
   CRect window_rect;
   int window_width;
   int window_height;

   GetWindowRect(&window_rect);
   window_width = window_rect.Width();
   window_height = window_rect.Height();

   SetScrollSizes(MM_TEXT, CSize(window_width,
                                    window_height));

   return(0);
}

However, the following function does not add scrollbars:

int CMoveView::ScrollTest()
{
   CRect window_rect;
   int window_width;
   int window_height;

   GetWindowRect(&window_rect);
   window_width = window_rect.Width();
   window_height = window_rect.Height();

   SetScrollSizes(MM_TEXT, CSize(window_width - 5,
                                    window_height - 5));

   return(0);
}

Why do I have to put this offset of 5?  I am afraid this offset value will probably
be different on different machines.  Am I misunderstanding how to use this function?
ASKER CERTIFIED SOLUTION
Avatar of milenvk
milenvk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaplan1

ASKER

Thanks!