Print Page | Close Window

How to handle Dynamic created menus Event Handling

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=11335
Printed Date: 15 November 2025 at 8:53am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to handle Dynamic created menus Event Handling
Posted By: Pariksh*t
Subject: How to handle Dynamic created menus Event Handling
Date Posted: 08 July 2008 at 12:44am

hi

this is pariksh*t.

i am implementing dynamic menus in a ribbonbar.

i amthrough with that.

i am handling all the events of this menu whose ids gets dynamically created in function----

BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);

But the problem is that

the menu items are disabled as i have not done

void OnUpdate11111(CCmdUI* pCmdUI);

void On11111();

11111 is the id of a menu item. This id is dynamically generated....if i dont write these 2 functions my menu items gets disabled
Now the issue is at the compile time i have no idea about no of menu items which will generate at run time
so i cant write
void OnUpdate#(CCmdUI* pCmdUI);
void On#();
at compile time
what should i do?
 
Reply asap.
 
Regards,
Pariksh*t.



Replies:
Posted By: Oleg
Date Posted: 08 July 2008 at 6:25am
Hi,
 
How it worked before with simple CMenu ? I sure it will work same with our CommandBars.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Pariksh*t
Date Posted: 08 July 2008 at 7:06am

Dear oleg

thanx for reply

But i didnt get you. There is no issue with your commandbars or menus the question was about how to do event handling of dynamically generated menus in Xtreme toolkit.

i managed to do the same in mfc in a dialog based app.

But problem with Xtreme Toolkit is that it compells me to write OnUpdate#() and On#() for each & every ID of menu which generates at run time

and the no of IDs is not fixed ............
do reply


Posted By: Smucker
Date Posted: 08 July 2008 at 8:15am
All you should need are:

ON_UPDATE_COMMAND_UI_RANGE
ON_COMMAND_RANGE



-------------
Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)

Platform: Windows 200x/XP/Vista/Win7 (32/64 bit)

Language: Visual C++ 9.0 (Studio 2008)



Posted By: Pariksh*t
Date Posted: 08 July 2008 at 10:54pm
thanx
 
but for RANGE you should know the 1st and last id
in my case i know  1st id but not the last one as it generates at run time
so the problem is still not resolved.................
 
do reply.....
 


Posted By: Smucker
Date Posted: 09 July 2008 at 1:53am
Just define an arbitrary maximum; surely 1000 should be more than enough; for example:

#define IDC_DYNAMIC_FIRST 20000
#define IDC_DYNAMIC_LAST 20999


If you need different ranges for different things (I do), just use separate ranges for each.

If you need to assign IDs arbitrarily to different functions, use an array of structures indexed by [id - IDC_DYNAMIC_FIRST] to locate a structure that defines what that particular ID does (for example, a call to a named macro).



-------------
Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)

Platform: Windows 200x/XP/Vista/Win7 (32/64 bit)

Language: Visual C++ 9.0 (Studio 2008)



Posted By: Pariksh*t
Date Posted: 09 July 2008 at 2:03am
hi
 
here in ur answer u r asuming that there will be maximum 999 ids which will get generate......what if there are more than 999 ids which generates at run time ?


Posted By: Smucker
Date Posted: 09 July 2008 at 2:52am
Then make it 10000 rather than 1000. How big of a menu do you think your users can deal with? Are you going to cover the entire screen with toolbar buttons?

If you need that many dynamically assigned IDs, I think you have a bigger problem than a fixed maximum.

By using an array indexed by ID as I mentioned, you can reuse IDs of removed items.



-------------
Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)

Platform: Windows 200x/XP/Vista/Win7 (32/64 bit)

Language: Visual C++ 9.0 (Studio 2008)



Posted By: Pariksh*t
Date Posted: 09 July 2008 at 4:25am
hi
 
yes i guess this is the last thing that i can do in this situation
but wait.....
 
in sdi an dmdi applications there is one variable
CFrameWnd::m_bAutoMenuEnable , using this variable with EnableMenuItem() can solve the problem
 
but my app is dialog based
 
thanx for 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