We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


ScrollView and Document

Paullkha asked
Medium Priority
Last Modified: 2013-11-20

I have a document. Its size is set as follows:
m_sizeDoc = CSize (100,100);
I have a view. In its OnInitialUpdate I have the following code:
void CMyView::OnInitialUpdate()
I am trying to prevent the frame window (view) from becoming larger than the doc size, which is 100,100.
I tried using WM_SIZE message to create CView::OnSize function that also has the following code:
void CMyView::OnSize(UINT nType, int cx, int cy)
CScrollView::OnSize(nType, cx, cy);
I get an assertion error.
What should I do to prevent my frame window becoming larger than my doc size?
Where does my code go, which functions do I override ,etc.

Watch Question

Process the following message in the frame
CWnd::OnGetMinMaxInfo (which is WM_GETMINMAXINFO )

Using this you can limit the size of the window.  You'll need to calculation border widths, caption allowances etc. by yourself but add this to the size and limit to that.  You can calculate the height of the caption etc. using GetSystemMetrics


In class wizard, it does not show that I can override this function.
I checked the VC++ help about OnGetMinMaxInfo. I do not need to worry about Minimizing or Maximizing.
I have a class derived from CScrollView. If I make my app full screen, I can RESIZE(grab the bottom left) my VIEW to be the full size of the app. This is not acceptable if my document size is smaller than my view size, at any given time. While I am resizing my view, I want to prevent its size from becoming larger than my doc size.
Unless I've completely misunderstood your question, this is the right message - it doesn't just apply to maximized/minimized windows - it also applies to tracking the size changes (when you drag the border of a window for example)

From the help - remarks section
The maximum tracking size is the largest window size that can be produced by using the borders to size the window. The minimum tracking size is the smallest window size that can be produced by using the borders to size the window.

Look at ptMinTrack size and ptMaxTrackSize in MINMAXINFO.

Good luck

ClassWizard (and the WizardBar and the context menu) aren't always right about what you can and can't (or should and shouldn't) overload.

Sometimes you have to manually overload a virtual function--or, worse, manually catch a Windows message--and then figure out such things as whether (and, if so, when) to call the base class version. Generally when the capablity was forgotten in ClassWizard the documentation is sketchy as well. Sometimes it helps to look at the actual MFC source for the parent class, but this doesn't always help.

In other words, just because ClassWizard tells you you can't overload OnGetMinMaxInfo or handle WM_GETMINMAXINFO doesn't mean you can't.


I might be out in left field. However, I added this code to my program:
void CMyView::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
      lpMMI->ptMaxTrackSize = CPoint(100,100);
afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI);

I put a break point on CMyView::OnGetMinMaxSize. This procedure is NEVER(???)triggered.

What am I not following? (What about OnSize? This procedure does trigger my break point when I resize the view.)

You need a message map entry too.


True. Thanks!
I added the following:
.Begin Message...      
.End Message...
However, it still behaves as stated

The short answer: You have to do this in your frame, not in your view.

As far as I can tell at a quick message-spying, the only windows that receive this in an MFC-built MDI app are the main frame and the MDI child frames; in an MFC-built SDI app, it's just the main frame.

Try moving the exact same code to your MDI child frame window and it should work.

You will need to adjust the desired view size (100x100) to include room for the border and the title bar in order to get the desired frame size.

payn said "The short answer: You have to do this in your frame, not in your view."

I said that 2 and half days ago in my original answer.  ditto on taking into account the captions and borders...


THANK YOU payn, for taking the time to analyze my code and find my error.

Answers2000, not everyone is as skilled as you in their understanding of MFC. It would have taken at most 4 lines of CODE to show me clearly what I was not understanding after I posted my comment showing CMyView::OnGetMinMaxInfo.
Answers2000, if you would like, please post an answer to this question so that I can give you points for providing me with the correct, albeit brief, original answer. If you are not interested, let me know so that I can give these points to payn.

I appreciate the help from both of you.
Unlock this solution and get a sample of our free trial.
(No credit card required)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.