-
October 21st, 2013, 11:36 PM
#1
Context menu creation
I would like to create a context menu,Its look something like this
HTML Code:
Delete ->Rung ->Start
->End
->Element
Exit
my code is
Code:
case WM_RBUTTONDOWN : //Right click option
{
MENUITEMINFO mi1,mi2={0};
HMENU hPopupMenu = CreatePopupMenu();
HMENU hSubMenu1 = CreatePopupMenu();
HMENU hSubMenu2 = CreatePopupMenu();
InsertMenu(hPopupMenu,0,MF_BYPOSITION|MF_STRING,ID_EDIT_EXTEND,_T("Exit"));
mi1.cbSize=sizeof(MENUITEMINFO);
mi1.fMask=MIIM_SUBMENU|MIIM_STRING|MIIM_ID;
mi1.wID=ID_EDIT_DELETE;
mi1.hSubMenu=hSubMenu1;
mi1.dwTypeData=_T("Delete");
InsertMenu(hSubMenu1,0,MF_BYPOSITION|MF_STRING,ID_DELETE_ELEMENT,_T("Element"));
InsertMenu(hSubMenu1,0,MF_BYPOSITION|MF_STRING,ID_DELETE_RUNG,_T("Rung"));
mi2.cbSize=sizeof(MENUITEMINFO);
mi2.fMask=MIIM_SUBMENU|MIIM_STRING|MIIM_ID;
mi2.wID=ID_DELETE_RUNG;
mi2.hSubMenu=hSubMenu2;
mi2.dwTypeData=_T("Rung");
InsertMenu(hSubMenu2,0,MF_BYPOSITION|MF_STRING,ID_DELETE_START,_T("Start"));
InsertMenu(hSubMenu2,0,MF_BYPOSITION|MF_STRING,ID_DELETE_END,_T("End"));
InsertMenuItem(hSubMenu1,0,false,&mi2);
InsertMenuItem(hPopupMenu,0,false,&mi1);
SetForegroundWindow(hWnd);
GetCursorPos(&ptClient);
TrackPopupMenuEx(hPopupMenu,0,ptClient.x,ptClient.y,hWnd,NULL);
}
But i am getting Output Like this
HTML Code:
Delete ->Rung
->Element
->Rung ->Start
->End
Exit
What modification i have to do for the desired output
-
October 22nd, 2013, 01:27 AM
#2
Re: Context menu creation
The item "Rung" is popup menu. so it needs flag MF_POPUP and a menu handle rather than a menu item ID to be passed in the InsertItem... call
Victor Nijegorodov
-
October 22nd, 2013, 02:22 AM
#3
Re: Context menu creation
I did a modification like this,& its working,But i dont know its correct or not
Code:
case WM_RBUTTONDOWN : //Right click option
{
MENUITEMINFO mi1,mi2={0};
HMENU hPopupMenu = CreatePopupMenu();
HMENU hSubMenu1 = CreatePopupMenu();
HMENU hSubMenu2 = CreatePopupMenu();
InsertMenu(hPopupMenu,0,MF_BYPOSITION|MF_STRING,ID_EDIT_EXTEND,_T("Exit"));
mi1.cbSize=sizeof(MENUITEMINFO);
mi1.fMask=MIIM_SUBMENU|MIIM_STRING|MIIM_ID;
mi1.wID=ID_EDIT_DELETE;
mi1.hSubMenu=hSubMenu1;
mi1.dwTypeData=_T("Delete");
InsertMenu(hSubMenu1,0,MF_BYPOSITION|MF_STRING,ID_DELETE_ELEMENT,_T("Element"));
//InsertMenu(hSubMenu1,0,MF_BYPOSITION|MF_STRING,ID_DELETE_RUNG,_T("Rung"));
mi2.cbSize=sizeof(MENUITEMINFO);
mi2.fMask=MIIM_SUBMENU|MIIM_STRING|MIIM_ID;
mi2.wID=ID_DELETE_RUNG;
mi2.hSubMenu=hSubMenu2;
mi2.dwTypeData=_T("Rung");
InsertMenu(hSubMenu2,0,MF_BYPOSITION|MF_STRING,ID_DELETE_START,_T("Start"));
InsertMenu(hSubMenu2,0,MF_BYPOSITION|MF_STRING,ID_DELETE_END,_T("End"));
InsertMenuItem(hSubMenu1,0,true,&mi2);
InsertMenuItem(hPopupMenu,0,false,&mi1);
SetForegroundWindow(hWnd);
GetCursorPos(&ptClient);
TrackPopupMenuEx(hPopupMenu,0,ptClient.x,ptClient.y,hWnd,NULL);
}
break;
-
October 22nd, 2013, 02:47 AM
#4
Re: Context menu creation
Originally Posted by manjut19
I did a modification like this,& its working,But i dont know its correct or not
What is your doubt in and why?
Or, at least, define "its working"
Victor Nijegorodov
-
October 23rd, 2013, 04:31 AM
#5
Re: Context menu creation
Originally Posted by VictorN
What is your doubt in and why?
Or, at least, define "its working"
Its working as desired,But I don;t know code wise its correct
-
October 23rd, 2013, 07:04 AM
#6
Re: Context menu creation
Originally Posted by manjut19
I would like to create a context menu
Are you aware of the fact that context menu is just a popup menu, and can be a menu resource alright?
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|