Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 484
  • Last Modified:

ScrollView and Document

Hello,

I have a document. Its size is set as follows:
CMyDoc::InitDoc()
m_sizeDoc = CSize (100,100);
I have a view. In its OnInitialUpdate I have the following code:
void CMyView::OnInitialUpdate()
{
...
GetParentFrame()->RecalcLayout();
ResizeParentToFit(TRUE);
CScrollView::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);
GetParentFrame()->RecalcLayout();
ResizeParentToFit(TRUE);
}
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.


}
0
Paullkha
Asked:
Paullkha
  • 4
  • 4
  • 2
  • +1
1 Solution
 
Answers2000Commented:
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

0
 
PaullkhaAuthor Commented:
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.
Clarification:
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.
0
 
Answers2000Commented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
paynCommented:
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.

0
 
PaullkhaAuthor Commented:
I might be out in left field. However, I added this code to my program:
MyView.cpp
void CMyView::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
      lpMMI->ptMaxTrackSize = CPoint(100,100);
}
MyView.h
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.)

0
 
dvazquezCommented:
You need a message map entry too.
0
 
PaullkhaAuthor Commented:
True. Thanks!
I added the following:
.Begin Message...      
ON_WM_GETMINMAXINFO()
.End Message...
However, it still behaves as stated
0
 
paynCommented:
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.


0
 
Answers2000Commented:
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...
0
 
PaullkhaAuthor Commented:
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.
0
 
Answers2000Commented:
Thanks, sorry I wasn't clearer at the start, but after having my original answer rejected, I thought it better to keep a low profile :-)

I hadn't realized you had missed the message map entry, it didn't show up in your original fragment or comments, so it simply never occured to me that that was an additional problem area in your program.

Anyway I'm glad you've got it working now.
0

Featured Post

Technology Partners: 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!

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now