Solved

CScrollView in a static CSplitterWnd pane

Posted on 1997-04-06
10
966 Views
Last Modified: 2013-11-20
I am trying to put a CScrollView-derived view in
the lower right pane of a CSplitterWnd with 4 static
panes, using MSVC 4.0.  The other three panes are
derived from CView.

This worked fine in my last 16-bit app (MSVC 1.52)
but with MSVC 4.0, calling ResizeParentToFit() from
the OnSize() method of CScrollView only works properly
if both dimensions of the pane are smaller than the
logical view size (and both the horiz and vert
scrollbars appear).  If only one dimension is smaller,
then 1 scrollbar should appear, but it doesn't.

Stepping through the OnSize() code, the scrollbar actually
does appear, but disappears shortly thereafter (I believe
that it disappears when the View background is erased).  
The scrollbar disappears sometime after all OnSize()
methods have been processed by the four views, the
CSplitterWnd, and the enclosing CFrameWnd.  It is gone by
the time CScrollView::OnDraw() is called.  I don't know
what else to trap to narrow down the problem.
0
Comment
Question by:pschimpf
10 Comments
 

Author Comment

by:pschimpf
ID: 1300883
Adjusted points to 100
0
 
LVL 4

Expert Comment

by:mbhakta
ID: 1300884
If you read your Visual C++ docs carefully under the topic ResizeParentToFit() it says, this call should be used in the OnInitialUpdate() functions and guarantees no rational behaviour if misused. There might lie the answer for your problem.
0
 

Author Comment

by:pschimpf
ID: 1300885
The Visual C++ on-line references state that you should call
ResizeParentToFit() from OnInitialUpdate(), but NOT that this
is the ONLY place it should be called from.  In fact, if you
look at the help for SetScrollSizes() you will see an example
implementation of OnUpdate() that calls ResizeParentToFit().
This is the same place that I am calling it from, so there is
no reason to conclude that I am misusing it.
0
 

Author Comment

by:pschimpf
ID: 1300886
Adjusted points to 200
0
 

Author Comment

by:pschimpf
ID: 1300887
Edited text of question
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:pschimpf
ID: 1300888
Sorry, I am actually calling ResizeParentToFit() from OnSize(),
not OnUpdate(), but I still see no reason that this is a
misuse of ResizeParentToFit().  It is actually the logical
place to call it from, because I wish the view window to be
no larger than the actual size of the document.  If the user
resizes the window to be larger (which results in a call to
OnSize()), then a call to ResizeParentToFit() should reduce
the view window back down to the proper size, and it does!
Its just that under the right circumstances, it also removes
a scroll bar, which it should not do.
0
 
LVL 1

Expert Comment

by:rhgaracci
ID: 1300889
Try the following in OnSize() instead of calling the CScrollView::OnSize()

CView::OnSize(nType, cx, cy);
ResizeParentToFit();
UpdateBars();
0
 

Author Comment

by:pschimpf
ID: 1300890
Interesting (because MSVC 4.0 has no help entry for
UpdateBars(), but it did compile).  Unfortunately,
it didn't help.  I do have a new clue, however:
I normally run with:
 
Control Panel/Display/Plus!/Show Window Contents while Dragging
turned off (not checked)

But if I turn it on, my Splitter window flickers as the Window
is being resized.  You can see it draw the scrollbar at the
stretched out size and then snap back to the ResizeWindowToFit()
size - without the ScrollBars being redrawn!  AND, a final
snap back to the ResizeParentToFit() size doesn't happen when
the mouse button is released - although it DOES when Show
Window Contents while Dragging is off!

It seems like the OnSize() method is being called while the
window is being resized, but the documentation says that it
should be called when the resizing is complete (i.e., when
you release the mouse button).  The documentation also discusses
another member function:  OnSizing() as opposed to OnSize().
But guess what?  The class wizard won't let you connect
OnSizing()!  Is the message map calling OnSize() when it should
be calling OnSizing()?  If so, is there a fix?  

If someone wants to play with this, I would be glad to email them
a small project that illustrates the problem.  Contact me at
Paul_Schimpf@atk.com.  If you find a fix, I will give you an
Excellent score, no matter how kludgy the fix is.  I'm convinced
that this is a hard one.  I'll increase the points as they become
available to me.

0
 

Author Comment

by:pschimpf
ID: 1300891
OK, I have an answer:

Do NOT call ResizeParentToFit() from inside OnSize().
Instead, use PostMessage() to post a user-defined message.
Create a handler for that user-defined message that calls
ResizeParentToFit().

This works, although I have no satisfactory explanation for
why calling ResizeParentToFit() from OnSize() directly doesn't,
and neither does Microsoft Tech support, although they have
aknowledged the problem and suggested this fix.

They also suggested creating my own ResizeToFit at the frame
window level.  At this level though, you have to account for
the width of scrollbars and splitter bars, etc.  Any easy way
to do that might be to start by maximizing everything by calling
ResizeParentToFit(FALSE) in the OnInitialUpdate() method of
the CScrollView-derived class, then recording the size of the
frame window client area, and then not allow the frame window
area to be stretched beyond that size in the OnSizing() method
of the frame window.  Of course, if you have zoom levels (like
I do), it gets a little more complicated...

0
 
LVL 2

Accepted Solution

by:
cathys earned 200 total points
ID: 1300892
(submitted for pschimpf)

OK, I have an answer:

Do NOT call ResizeParentToFit() from inside OnSize().
Instead, use PostMessage() to post a user-defined message.
Create a handler for that user-defined message that calls
ResizeParentToFit().

This works, although I have no satisfactory explanation for
why calling ResizeParentToFit() from OnSize() directly doesn't,
and neither does Microsoft Tech support, although they have
aknowledged the problem and suggested this fix.

They also suggested creating my own ResizeToFit at the frame
window level. At this level though, you have to account for
the width of scrollbars and splitter bars, etc. Any easy way
to do that might be to start by maximizing everything by calling
ResizeParentToFit(FALSE) in the OnInitialUpdate() method of
the CScrollView-derived class, then recording the size of the
frame window client area, and then not allow the frame window
area to be stretched beyond that size in the OnSizing() method
of the frame window. Of course, if you have zoom levels (like
I do), it gets a little more complicated...

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 94
Pressing cancel button with C# UI Automation 3 51
Looking for a specific application/software 2 104
Detect CR LF to each line 12 152
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

15 Experts available now in Live!

Get 1:1 Help Now