Parent/child messaging problem... 
Author Message
 Parent/child messaging problem...

Hello all,

I apologize if I'm just really missing the boat on this one, but I've
researched it in the MSDN docs and on DejaNews without any luck so I thought
I'd try here...

I'm writing an MFC Doc/View app whose View is composed of multiple child
windows.  Each child window class is derived from my View class (which, itself,  
is derived from CView) and each has its own message map.  One of the child
windows, which displays text from a text buffer, has a vertical scroll bar.  

The problem: I only receive WM_VSCROLL messages in my View message map, not in
the child window's message map.  I think I understand correctly that this is a
feature (not a bug) of MFC that messages generated in a child window are routed
to the parent window (in this case, my View object).  (Why this is desirable I
don't quite understand, but that's another story...)

I did learn of the ON_WM_VSCROLL_REFLECT() macro which, if I understand the
MSDN docs correctly, I should place in my child window's message map so that
the WM_VSCROLL messages stay in the child window's class.  I did that, and
changed my OnVScroll override to VScroll.  But (you guessed it) that did not
work.  Clicking on the vertical scroll bar does not cause my VScroll override
to be called.  

Should this have worked (meaning I've screwed something else up) or am I on the
wrong track?  

Thanks very much for any guidance.  

Andy.  

--



Fri, 10 Aug 2001 03:00:00 GMT  
 Parent/child messaging problem...
Andrew:

First of all, it is a bit unusual to use a CView for any purpose other than placing
in a frame window -- why did you not just use a CWnd derivative?

Second, this child window which has the scrollbar -- is this its own scrollbar, or
a child window of the child? But in either case, these messages should be going to
your child view, not to the original parent view. Are you sure this is not
happening?

Remember, though, because of the way you have done the class inheritance:

CView -> CParentView -> CChildView

you have five instances of CParentView (and CView) running. When you receive
messages in the code of CParentView, it may be in fact servicing messages of the
CChildView (if the child view did not handle them itself). This possible confusion
would have been avoided if you had not derived your child views from the same class
which you used as the view. I really would recommend using CWnds for these child
windows.

As an aside, this business of sending control notifications to the parent is
Windows' doing, not MFC's. In regular Windows programming it is a pain to change
the messaging behavior of a window for which you did not write the code (like a
control), so it is much easier to handle the messages in the parent, whose message
handler (the window procedure) you write yourself. In MFC it is much easier to
alter the messages handling of the child control, and so message refection is very
useful. But I do not think this is the issue here.

HTH,

David Wilkinson

======================

Quote:

> Hello all,

> I apologize if I'm just really missing the boat on this one, but I've
> researched it in the MSDN docs and on DejaNews without any luck so I thought
> I'd try here...

> I'm writing an MFC Doc/View app whose View is composed of multiple child
> windows.  Each child window class is derived from my View class (which, itself,
> is derived from CView) and each has its own message map.  One of the child
> windows, which displays text from a text buffer, has a vertical scroll bar.

> The problem: I only receive WM_VSCROLL messages in my View message map, not in
> the child window's message map.  I think I understand correctly that this is a
> feature (not a bug) of MFC that messages generated in a child window are routed
> to the parent window (in this case, my View object).  (Why this is desirable I
> don't quite understand, but that's another story...)

> I did learn of the ON_WM_VSCROLL_REFLECT() macro which, if I understand the
> MSDN docs correctly, I should place in my child window's message map so that
> the WM_VSCROLL messages stay in the child window's class.  I did that, and
> changed my OnVScroll override to VScroll.  But (you guessed it) that did not
> work.  Clicking on the vertical scroll bar does not cause my VScroll override
> to be called.

> Should this have worked (meaning I've screwed something else up) or am I on the
> wrong track?

> Thanks very much for any guidance.

> Andy.

> --




Fri, 10 Aug 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Parent/child messaging problem...

2. keyboard message notification from a child window to the parent window

3. Processing a message the parent before the child window

4. How can a parent frame receive a message of a child control

5. Handle a child message in parent

6. How parent window captures message destined to child window

7. Sending a message to a parent CView from a child CWnd

8. Child instructing parent to delete child.

9. Problem: React on Child-Dialog from Parent-Dialog

10. Moving Child Window with parent problem(WM_MOVE)

11. Modeless Dialog parent and child minmize problem.

12. Q: problem processing ON_CONTROL_REFLECT_EX messages in parent dialog

 

 
Powered by phpBB® Forum Software