Print Page | Close Window

Enabling Menu Items without code handlers

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=11086
Printed Date: 01 March 2025 at 3:06am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Enabling Menu Items without code handlers
Posted By: BobWansink
Subject: Enabling Menu Items without code handlers
Date 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



Replies:
Posted By: Oleg
Date 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


Posted By: Smucker
Date 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.



Posted By: BobWansink
Date 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!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net