Handling a menu in a dialog.
Hi,
I have a dialog based application for which I use a menu.
The problem that I am facing is that when I place the handler for the menu item in the dialog class everything works fine. But if I move the handler to the app class, then the menu item is not being handled.
Could anyone please let me know why is this so?
Re: Handling a menu in a dialog.
May I ask a different question first? Why would you like to handle a menu entry of the dialog inside the application class?
Re: Handling a menu in a dialog.
Hi Andreas,
It is a question out of sheer curiosity.
I was just helping one of my friends with VC++/MFC when we stumbled upon this problem. He was trying out a dialog based application. A menu waas associated with the same and he tried to put in the menu handler in the app class which did not work.
This kindled our interest and since we could not come up with any logical reasoning, I thought I would put it up here.
Re: Handling a menu in a dialog.
Oh...okay I see...in (very) short terms...
Why would a message handler of the application class being called. Think about it from a logical point...the menu is attached to the dialog class and interacts with it through the lifetime of the dialog. Thus, it is a kind of parent/child relation. The child does not know anything about the grandparent (-> the application class).
This is of course only a limited explanation, but I am afraid that IO cannot go into all the deails of the MFC here...
Re: Handling a menu in a dialog.
Hi Andreas,
But then in case of Doc-View doesn't the handler fall into the sequence below?
View
Doc
FrameWnd
App.
Re: Handling a menu in a dialog.
I'm not very sure about this, but when you launch the dialog with CDialog::DoModal(), the message loop is being run by windows. So any wm_command messages are routed thru CDialog. CWinApp doesnt come into the pic until the call to DoModal returns.
Like I said, im not very sure about this. My mfc (what there is) is pretty rusty. But this sounds pretty interesting...
Re: Handling a menu in a dialog.
Thank you Andreas and Raghupathys