Dynamic Menu Creation
-
Hi I have created a menu using Resource. for example--> A and below I want to add one menu named B dynamically. How to do that.
-
Hi I have created a menu using Resource. for example--> A and below I want to add one menu named B dynamically. How to do that.
CMenu menu;
menu.LoadMenu(IDR_RESOURCEMENU);
CMenu* pContextMenu = menu.GetSubMenu(1);pContextMenu->InsertMenu(0, MF\_STRING | MF\_BYPOSITION, ID\_LISTMENU\_OPEN, \_T("&Open")); pContextMenu->InsertMenu(1, MF\_SEPARATOR | MF\_BYPOSITION, 0); // insert your menu at index 0 (first position) pContextMenu->SetDefaultItem(0, TRUE); // put the inserted menu as default
ID_LISTMENU_OPEN
must declared somewhere in your app, as UINT Hope it help you ... -
CMenu menu;
menu.LoadMenu(IDR_RESOURCEMENU);
CMenu* pContextMenu = menu.GetSubMenu(1);pContextMenu->InsertMenu(0, MF\_STRING | MF\_BYPOSITION, ID\_LISTMENU\_OPEN, \_T("&Open")); pContextMenu->InsertMenu(1, MF\_SEPARATOR | MF\_BYPOSITION, 0); // insert your menu at index 0 (first position) pContextMenu->SetDefaultItem(0, TRUE); // put the inserted menu as default
ID_LISTMENU_OPEN
must declared somewhere in your app, as UINT Hope it help you ...@Flaviuu Thanx for the reply Its not working for me void CmainWn::OnBZ() { // TODO: Add your command handler code here CMenu menu; menu.LoadMenuA(IDR_MENU1); CMenu* pcontextmenu=menu.GetSubMenu(0); pcontextmenu->InsertMenuA (0,MF_STRING|MF_BYPOSITION,ID_SHOW,_T("&Open")); pcontextmenu->InsertMenuA(1,MF_SEPARATOR|MF_BYPOSITION,0); pcontextmenu->SetDefaultItem(0,TRUE); } I added this code on the event handler of menu Z which is under menu B at location 0. But it is not working for me. My objective is here is on the click of menu Z one menu should be added in my main menu(IDR_MENU1) named as A Correct me If I am wrong somewhere.
-
@Flaviuu Thanx for the reply Its not working for me void CmainWn::OnBZ() { // TODO: Add your command handler code here CMenu menu; menu.LoadMenuA(IDR_MENU1); CMenu* pcontextmenu=menu.GetSubMenu(0); pcontextmenu->InsertMenuA (0,MF_STRING|MF_BYPOSITION,ID_SHOW,_T("&Open")); pcontextmenu->InsertMenuA(1,MF_SEPARATOR|MF_BYPOSITION,0); pcontextmenu->SetDefaultItem(0,TRUE); } I added this code on the event handler of menu Z which is under menu B at location 0. But it is not working for me. My objective is here is on the click of menu Z one menu should be added in my main menu(IDR_MENU1) named as A Correct me If I am wrong somewhere.
-
You should explain better: what you call "Menu Z" ? If I understand well, you have a resource menu, IDR_MENU1, where you want to add dynamically an menu item, ID_SHOW ... I am right ? P.S. If you post code, use
tag ...
@Flaviuu I have defined Menu Z its entry in resource file is ID_B_Z . Yes you are right I am having a resource menu IDR_MENU1 where I want to add a menu named ID_SHOW dynamically. I just want to know what is wrong with my code ?
-
@Flaviuu I have defined Menu Z its entry in resource file is ID_B_Z . Yes you are right I am having a resource menu IDR_MENU1 where I want to add a menu named ID_SHOW dynamically. I just want to know what is wrong with my code ?
-
@Flaviuu Yes I have defined it in my Resource.h file like this. #define ID_SHOW 107
-
@Flaviuu Yes I have defined it in my Resource.h file like this. #define ID_SHOW 107
-
@Flaviuu Thanx for the reply Its not working for me void CmainWn::OnBZ() { // TODO: Add your command handler code here CMenu menu; menu.LoadMenuA(IDR_MENU1); CMenu* pcontextmenu=menu.GetSubMenu(0); pcontextmenu->InsertMenuA (0,MF_STRING|MF_BYPOSITION,ID_SHOW,_T("&Open")); pcontextmenu->InsertMenuA(1,MF_SEPARATOR|MF_BYPOSITION,0); pcontextmenu->SetDefaultItem(0,TRUE); } I added this code on the event handler of menu Z which is under menu B at location 0. But it is not working for me. My objective is here is on the click of menu Z one menu should be added in my main menu(IDR_MENU1) named as A Correct me If I am wrong somewhere.
Thakur JAI SINGH wrote:
But it is not working for me.
What specifically is not working? You have 5 statements here. Have you stepped through each one using the debugger to see which one is not working as expected?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles