Solved

Resize viewable area in FormView

Posted on 1998-08-28
6
1,117 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
  • 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now