Solved

Resize viewable area in FormView

Posted on 1998-08-28
6
1,118 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

13 Experts available now in Live!

Get 1:1 Help Now