-
adding menus at runtime
i dont like making menus at design time, because i like to be able to modify anything about my program that i want, including menus. but i cant get the code exactly right. heres what im doing at the moment:
Code:
HMENU hMenu;
HMENU hPopUp;
hMenu=CreateMenu();
hPopUp=CreatePopupMenu();
AppendMenu(hPopUp,MF_STRING,ID_EXIT,"E&xit");
AppendMenu(hMenu,MF_POPUP,(int)hPopUp,NULL);
if (SetMenu(hwnd,hMenu))
Notify(hwnd,"success"); //my own routine, its just a messagebox
unfortunately a menu doesn't appear, but there is a small buffer area at the top of the client area, about half the height of a menu bar. why wont the code work?
-
Appendmenu() is obslete. Try playing with this code
Code:
#define ID_PAGE_1 40001
for(i=0;i<MaxPages;i++)
{
//set the text
sprintf(sBuffer,"Page %d of %d.",i+1,MaxPages);
//fill the structure
MenuItemInfo.cbSize=sizeof(MENUITEMINFO);
MenuItemInfo.fMask=MIIM_DATA| MIIM_ID| MIIM_TYPE| MIIM_ID| MIIM_CHECKMARKS |MIIM_STATE |MIIM_SUBMENU;
MenuItemInfo.fType=MFT_STRING;
MenuItemInfo.dwTypeData=sBuffer;
MenuItemInfo.hbmpChecked=NULL;
MenuItemInfo.hbmpUnchecked=NULL;
MenuItemInfo.fState=MFS_ENABLED;
MenuItemInfo.hSubMenu=NULL;
MenuItemInfo.wID=ID_PAGE_1+i;
InsertMenuItem(hPageMenu,i,TRUE,&MenuItemInfo);
}
-
Try changing your last AppendMenu( ) to this...
Code:
AppendMenu( hMenu, MF_STRING | MF_POPUP, (UINT)hPopUp, "&File" );
-
thanks mr wizard, it works now. that was pretty silly of me, i mean, you cant have a menu without a caption.
sorry novacain, i didn't get to finish implementing your method, when i found that it was easier the way i was doing it. i understand though that using InsertMenuItem gives you more options and capabilities, so next time i need those things i'll use your method.