Confusion about "OnCommand" function. - Programmer

This is a discussion on Confusion about "OnCommand" function. - Programmer ; Hi. I am trying to learn how the "OnCommand" function works with menus in MFC. The documentation for CWD::OnCommand says, "The framework calls this member function when the user selects an item from a menu..." I added a menu item ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Confusion about "OnCommand" function.

  1. Confusion about "OnCommand" function.

    Hi.

    I am trying to learn how the "OnCommand" function works with menus in
    MFC.

    The documentation for CWD::OnCommand says, "The framework calls this
    member function when the user selects an item from a menu..."

    I added a menu item to the main menu. Then I used Class Wizard to
    override OnCommand. When I ran the program, my menu item was
    greyed-out, so I set my frame window's m_bAutoEnable member to
    "FALSE."

    I ran the program again, and this time my menu item was enabled, but
    when I clicked the menu item, the OnCommand function was not called.

    Why wasn't the OnCommand function called? Many thanks for anyone who
    can help me. - Tony

  2. Re: Confusion about "OnCommand" function.

    Depends whos OnCommand you are overriding. You should override CFrameWnd's.
    But anyway, things are generally not done that way. Most of the time you
    would let OnCommand dispatch the message automatically.
    You see for every Menu item you want to handle you would have a
    ON_COMMAND(id,MemberFunc) entry in your message map, and an
    ON_UPDATE_COMMAND_UI(id, memberfunc) if you want to control whether the menu
    is enabled, disabled, checked or what not.


    Ali R.

    "TonyVarden" wrote in message
    news:739e44f7.0311231558.6ad6e18b@posting.google.c om...
    > Hi.
    >
    > I am trying to learn how the "OnCommand" function works with menus in
    > MFC.
    >
    > The documentation for CWD::OnCommand says, "The framework calls this
    > member function when the user selects an item from a menu..."
    >
    > I added a menu item to the main menu. Then I used Class Wizard to
    > override OnCommand. When I ran the program, my menu item was
    > greyed-out, so I set my frame window's m_bAutoEnable member to
    > "FALSE."
    >
    > I ran the program again, and this time my menu item was enabled, but
    > when I clicked the menu item, the OnCommand function was not called.
    >
    > Why wasn't the OnCommand function called? Many thanks for anyone who
    > can help me. - Tony




+ Reply to Thread