Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Enabling Menu Items without code handlers
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Enabling Menu Items without code handlers

 Post Reply Post Reply
Author
Message
BobWansink View Drop Down
Groupie
Groupie
Avatar

Joined: 24 January 2008
Status: Offline
Points: 59
Post Options Post Options   Thanks (0) Thanks(0)   Quote BobWansink Quote  Post ReplyReply Direct Link To This Post Topic: Enabling Menu Items without code handlers
    Posted: 18 June 2008 at 5:12am
Hi!

I've added a CXTPMenuBar to a CWnd derived panel. I've stumbled onto another problem, and I hope you know the answer to this.

The menu isn't loaded with a reference, but with a CMenu. The CMenu is generated automatically in our software. The menuitems are greyed at the moment, since there isn't a handler for their id's. How can I activate these menu's?

Thanks!

Bob
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 18 June 2008 at 7:06am
Hi,
 
So you don't know what Ids will CMenu have ? How you want to catch Click event in this case ?
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
Smucker View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 February 2008
Status: Offline
Points: 156
Post Options Post Options   Thanks (0) Thanks(0)   Quote Smucker Quote  Post ReplyReply Direct Link To This Post Posted: 18 June 2008 at 1:51pm
I'm not sure if this is similar enough to your situation to be of use, but here's an idea.

I had my own table-based command enabler/grayer/checker code which I didn't want to replace with a separate method for each of hundreds of commands.

I created a message map entry as follows:

    ON_UPDATE_COMMAND_UI_RANGE(CMD_FIRST, CMD_LAST, UpdateCmdUI)

UpdateCmdUI is defined as follows:

void CMainFrame::UpdateCmdUI(CCmdUI* pcmdui)
{
#define LAG_CMDUI 200
    static DWORD curtime = 0,lasttime = 0;

    if ( (curtime = ::GetTickCount()) > lasttime + LAG_CMDUI) {
        ::UpdateCommandStates(cmd_table, NULL, NULL);
        lasttime = ::GetTickCount();
    }
    for (int i=0; ::cmd_table[i].id != 0; i++) {
        if (pcmdui->m_nID == (UINT)::cmd_table[i].id) {
            pcmdui->SetCheck((BOOL)::cmd_table[i].state & MF_CHECKED);
            pcmdui->Enable(!(::cmd_table[i].state & (MF_DISABLED|MF_GRAYED)));
        }
    }
}


UpdateCommandStates processes all commands and sets the flags appropritely in cmd_table. The 200 ms lag time keeps it from running repeatedly.

Of course, if you just always want them enabled, you could just call pcmdui->Enable.

Back to Top
BobWansink View Drop Down
Groupie
Groupie
Avatar

Joined: 24 January 2008
Status: Offline
Points: 59
Post Options Post Options   Thanks (0) Thanks(0)   Quote BobWansink Quote  Post ReplyReply Direct Link To This Post Posted: 20 June 2008 at 6:41am
hi all,

I've managed to solve it with a combination of ON_COMMAND_RANGE and some of our own functions. The menu items are now selectable and transmit their message correctly.

Thanks for the help!
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.078 seconds.