CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2002
    Location
    India
    Posts
    268

    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?
    Life is short, enjoy it with a smile as long as it lasts.
    User error. Replace User and press any key when ready. - Anonymous

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    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?

  3. #3
    Join Date
    May 2002
    Location
    India
    Posts
    268

    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.
    Life is short, enjoy it with a smile as long as it lasts.
    User error. Replace User and press any key when ready. - Anonymous

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

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

  5. #5
    Join Date
    May 2002
    Location
    India
    Posts
    268

    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.
    Life is short, enjoy it with a smile as long as it lasts.
    User error. Replace User and press any key when ready. - Anonymous

  6. #6
    Join Date
    May 2002
    Location
    Phoenix, AZ
    Posts
    95

    Re: Handling a menu in a dialog.

    I'm not very sure about this, but when you launch the dialog with CDialog:oModal(), 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...

  7. #7
    Join Date
    May 2002
    Location
    India
    Posts
    268

    Re: Handling a menu in a dialog.

    Thank you Andreas and Raghupathys
    Life is short, enjoy it with a smile as long as it lasts.
    User error. Replace User and press any key when ready. - Anonymous

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured