Adding items to menu bar(similar to Add to favourites)
-
hi, i have a SDI application in which i want to add some text on the menus. for example the way we have the Add to Favourites in the Internet Explorer menu. so how do i implement that in my application. but in this case i want the data in a text box to be added (functionality is same as that of the Add to Favourites) . can anyone help. thanks aditya
-
hi, i have a SDI application in which i want to add some text on the menus. for example the way we have the Add to Favourites in the Internet Explorer menu. so how do i implement that in my application. but in this case i want the data in a text box to be added (functionality is same as that of the Add to Favourites) . can anyone help. thanks aditya
To insert a new item:
CMenu* m; m = AfxGetApp()->GetMainWnd()->GetMenu(); m = m->GetSubMenu(2);//change this to whatever (zero-based index). m->AppendMenu(MF_ENABLED,253,"new item");//change the second parameter to something you like. and the third one too.
When the menu item is clicked, you need a menu-command-range hander in the message-map macro in the .cpp file:ON_COMMAND_RANGE(200,400,OnMyMenu)//change the first and second parameter to the range you will provide in the second param to AppendMenu()
The implementation will be:void CMySdiView::OnMyMenu(UINT nItem) { }
Now nItem contains the second parameter you gave in AppendMenu(). So you know which one was clicked. One thing to note is that you must have at least a sub-item in the menu in the resource. Let it be a separator. When no sub-items are present, it gives a headache. this is this. -
hi, i have a SDI application in which i want to add some text on the menus. for example the way we have the Add to Favourites in the Internet Explorer menu. so how do i implement that in my application. but in this case i want the data in a text box to be added (functionality is same as that of the Add to Favourites) . can anyone help. thanks aditya
first u have to get a handle to the menu or create ur own HMENU hMenu = CreateMenu(); HMENU hPMenu = CreatePopupMenu(); AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT_PTR)hPMenu,favmenuTxt); AppendMenu(hPMenu,MF_STRING,favID,favTxt); also in ur message process u need to handle for the WM_COMMAND message with (i think) wParam being the command ID