![]() |
Enabling Menu Items without code handlers |
Post Reply ![]() |
Author | |
BobWansink ![]() Groupie ![]() ![]() Joined: 24 January 2008 Status: Offline Points: 59 |
![]() ![]() ![]() ![]() ![]() 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 |
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
Smucker ![]() Senior Member ![]() ![]() Joined: 02 February 2008 Status: Offline Points: 156 |
![]() ![]() ![]() ![]() ![]() |
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. |
|
![]() |
|
BobWansink ![]() Groupie ![]() ![]() Joined: 24 January 2008 Status: Offline Points: 59 |
![]() ![]() ![]() ![]() ![]() |
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! |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |