Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Resize viewable area in FormView

Posted on 1998-08-28
6
Medium Priority
?
1,149 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

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 400 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

688 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