Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Dynamic Menu Shared Handler?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Dynamic Menu Shared Handler?

 Post Reply Post Reply
Author
Message
robosport View Drop Down
Groupie
Groupie


Joined: 20 June 2005
Location: United States
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote robosport Quote  Post ReplyReply Direct Link To This Post Topic: Dynamic Menu Shared Handler?
    Posted: 27 April 2007 at 4:02am
Sorry for the newb-like question but I've never needed dynamically generated menus in an MFC/XTP app before.
 
When adding each new button to a popup menu I am giving each button a unique ID at run time. There are literally thousands of them in a relatively simply and organized menu hierarchy.
 
The question is: Do I need to enter a member function/procedure for each unique ID's event handler or is there a way to have a single shared handler for these dynamically generated buttons, that can simply accept the unique ID as a parameter and deal with it?
 
Thanks in advance.
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: 27 April 2007 at 6:54am
Hi,
 
You can use ON_COMMAND_RANGE macro:
ON_COMMAND_RANGE(MINRANGE, MAXRANGE, OnDynamicButtton)
 
void CMainFrame::OnDynamicButtton(UINT nButton)
{
}
 
or specific for XTP Menus: use same ID for all dynamic buttons but assign some parameter/integer data for CXTPControl.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
robosport View Drop Down
Groupie
Groupie


Joined: 20 June 2005
Location: United States
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote robosport Quote  Post ReplyReply Direct Link To This Post Posted: 27 April 2007 at 3:54pm

That was more of a newbie question than I thought and I'm suitably embarrassed. I learn something new every day. Thank you again Oleg!

Back to Top
robosport View Drop Down
Groupie
Groupie


Joined: 20 June 2005
Location: United States
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote robosport Quote  Post ReplyReply Direct Link To This Post Posted: 03 May 2007 at 3:50am
Okay, I went with the second option you suggested, namely the XTP specific one.
 
Another embarrassing question came up. If they use a shared ID (one handler procedure set with ON_COMMAND) and I place a custom value in the CXTPControlButton using SetTag for example when creating the menu items, how do I get a pointer to the CXTPControlButton pressed from the handler function (so I can retreive the custom value)?
 
The problem is ON_COMMAND handlers take no parameters so how do I get the CXTPControlButton that initated the command handler?
Back to Top
robosport View Drop Down
Groupie
Groupie


Joined: 20 June 2005
Location: United States
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote robosport Quote  Post ReplyReply Direct Link To This Post Posted: 03 May 2007 at 4:32am
I may have figured this out on my own.
 
Here is what I did:
- Derived a custom menu item class from CXTPControlButton
- Override OnLButtonUp for my derived menu item.
- When adding the dynamic menu item to the controls list I use the Add function that lets me pass in my derived control instead of the version that lets me pass the control type.
- I don't use ON_COMMAND at all for custom menu item handling.
 
This way works. Let me know if there is a better way.
 
Thanks.
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: 03 May 2007 at 5:22am
Hi,
 
your way is too difficult :) and user can press Enter instead click mouse.
 
easy way is use ON_XTP_EXECUTE macro:
 
ON_XTP_EXECUTE(ID_FAVORITE_LINK, OnFavorite)
 
 
void CMainFrame::OnFavorite(NMHDR* pNMHDR, LRESULT* pResult)
{
 NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
 AfxMessageBox(tagNMCONTROL->pControl->GetParameter());
 *pResult = 1;
}
 
check Samples\CommandBars\DynamicPopups it show how create dynamic favorites with same way.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
robosport View Drop Down
Groupie
Groupie


Joined: 20 June 2005
Location: United States
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote robosport Quote  Post ReplyReply Direct Link To This Post Posted: 03 May 2007 at 5:23am
Much better. Thank you!
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.061 seconds.