Thread: adding menus at runtime

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    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?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    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);
    	}
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Try changing your last AppendMenu( ) to this...

    Code:
    AppendMenu( hMenu, MF_STRING | MF_POPUP, (UINT)hPopUp, "&File" );

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    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.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. link with C runtime library
    By George2 in forum C++ Programming
    Replies: 26
    Last Post: 02-05-2008, 01:56 AM
  2. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 03:44 PM
  3. Adding commands to common context menus
    By Orderbringer in forum Windows Programming
    Replies: 2
    Last Post: 04-19-2005, 06:18 PM
  4. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  5. Adding Menuitems at runtime,
    By emus21 in forum Windows Programming
    Replies: 3
    Last Post: 06-23-2002, 08:39 PM