Solved

Resize viewable area in FormView

Posted on 1998-08-28
6
1,129 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:kaplan1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 2

Expert Comment

by:milenvk
ID: 1321459
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.

0
 

Author Comment

by:kaplan1
ID: 1321460
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).
0
 
LVL 2

Expert Comment

by:milenvk
ID: 1321461
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().
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!

 

Author Comment

by:kaplan1
ID: 1321462
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?
0
 
LVL 2

Accepted Solution

by:
milenvk earned 100 total points
ID: 1321463
Instead of GetWindowRect() you have to call GetClientRect(). GetWindowRect() returns the rectangle of the entire window, including boundaries, edges and captions. The view, however, expects to fit in the client rect, which means it is only displayed in the client area of the window, which normally is smaller than the window area. That's why when you subtract 5 from the width and height you get good results. That means that not the function but your test is wrong. Try it with GetClientRect(). And I can assure you that whatever these functions return it won't be different on different machines.
0
 

Author Comment

by:kaplan1
ID: 1321464
Thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question