tags:

views:

15

answers:

2

I need to send a WM_KEYDOWN message to all the Child Windows in my MDI app. The idea being that a particular key press refreshes a window and I want to refresh all child wnds at just a single key press. Other than refresh there would be couple of more such functions like right/left/up/down arrow keys etc. that need to go to each of these child wnds.

I am maintaining a list of all the available/eligible Child Windows in an STL List (being done during child window/view creation). Now, where can I capture a key press and pass it on to ALL the child windows in this list? Some specifics of the implementation would be appreciated as well.

After some soul and internet searching, I have came to conclusion that SendMessageToDescendants should be helpful. Now: 1. Where to call SendMessageToDescendants from 2. How to pass the params required by CView's OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) to void SendMessageToDescendants( UINT message, WPARAM wParam = 0, LPARAM lParam = 0, BOOL bDeep = TRUE, BOOL bOnlyPerm = FALSE );

A: 

I'm assuming you're maintaining the list of references/pointers to child windows in the parent, so couldn't you simply loop through that list, calling the KeyDown method of each child window in turn?

Rich.Carpenter
KeyDown event goes to the View and not to the MainFrame. So not sure how can I call the KeyDown of each view. If I call it utilizing the list of wnd pointers within a loop written in View's KeyDown itself, it becomes a recursive call. Adding bools etc to stop execution after first call is certainly not an elegant solution. :)
A: 

I think the key press goes to the window with the input focus, so if all the windows can have focus, you will need to resend to the other windows. I'm thinking PostMessage is your best bet here, without knowing a lot more about what you are doing.

UPDATE:

How will each View distinguish between a WM_KEYDOWN from the user, and the fake WM_KEYDOWN that is forwarded to all the Views? I'm thinking you need to re-think your solution - for instance, at WM_KEYDOWN, each View will call something like MainFrame::FakeKeyDown(). Then FakeKeyDown calls View::OnFakeKeyDown() for every view in your list of views, and you do whatever you need to do in the View.

Jeff
What I came to know is that SendMessageToDescendants will do the job for me. But am not too sure of its usage and where to call it from.