Dynamc Pop-up Menu?
-
Hi, I need to put together a context menu within an app that can display options that aren't known at compile time. I can create a normal pop-up menu alright I just don't know where to look to populate the menu with items that are, for instance, defined in a user configurable file. Any Ideas??? Josh Knox
We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin
-
Hi, I need to put together a context menu within an app that can display options that aren't known at compile time. I can create a normal pop-up menu alright I just don't know where to look to populate the menu with items that are, for instance, defined in a user configurable file. Any Ideas??? Josh Knox
We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin
If you are using MFC, you can use CMenu methods like AppendMenu. Following code snippet loads menu from resources and adds a separator and a dynamic menuitem:
void CMyView::OnContextMenu(CWnd* pWnd, CPoint point)
{
{
if (point.x == -1 && point.y == -1){
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; //You can optionaly load a static part of the menu from resources VERIFY(menu.LoadMenu(IDR\_CONTEXT\_MENU)); CMenu\* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); pPopup->AppendMenu(MF\_SEPARATOR); pPopup->AppendMenu(MF\_STRING,1111,"Dynamic"); CWnd\* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS\_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM\_LEFTALIGN | TPM\_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
If you want the menu completely dynamic, then add a MF_POPUP instead of LoadMenu. Pavel Sonork 100.15206
-
If you are using MFC, you can use CMenu methods like AppendMenu. Following code snippet loads menu from resources and adds a separator and a dynamic menuitem:
void CMyView::OnContextMenu(CWnd* pWnd, CPoint point)
{
{
if (point.x == -1 && point.y == -1){
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; //You can optionaly load a static part of the menu from resources VERIFY(menu.LoadMenu(IDR\_CONTEXT\_MENU)); CMenu\* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); pPopup->AppendMenu(MF\_SEPARATOR); pPopup->AppendMenu(MF\_STRING,1111,"Dynamic"); CWnd\* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS\_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM\_LEFTALIGN | TPM\_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
If you want the menu completely dynamic, then add a MF_POPUP instead of LoadMenu. Pavel Sonork 100.15206
Thanks Pavel, That'll work great. My next question is how to map commands to the dynamically added menu items? Josh Knox
We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin
-
Thanks Pavel, That'll work great. My next question is how to map commands to the dynamically added menu items? Josh Knox
We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin
Sorry I can't help you, but I had the same problem. I dynamically create a menu that contain a certain number of IP adresses, like : _TRAYMENU_ 192.168.0.1 62.43.12.10 etc... and I want to copy the IP to the clipboard when I click on it (I know for the clipborad, but I don't know how to map commands...) Thanks!
-
Sorry I can't help you, but I had the same problem. I dynamically create a menu that contain a certain number of IP adresses, like : _TRAYMENU_ 192.168.0.1 62.43.12.10 etc... and I want to copy the IP to the clipboard when I click on it (I know for the clipborad, but I don't know how to map commands...) Thanks!
Look up the DYNAMENU sample in MSDN. It details how to do this stuff. Josh Knox
We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin
-
Thanks Pavel, That'll work great. My next question is how to map commands to the dynamically added menu items? Josh Knox
We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin
Add an ON_COMMAND or ON_COMMAND_RANGE macros to the message map section of the class where you want to catch them:
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_DLLTEST, OnViewDlltest)
... and other macros added by class wizard
//}}AFX_MSG_MAP
ON_COMMAND(ID_xxxx, OnXxxx) //<<< manually add the handler mapping here
END_MESSAGE_MAP()You also need to add the void OnXxxx() method to your class. Pavel Sonork 100.15206