nimm

Hi i have a win32 application. I was able to create a popup menu. but unable to insert a submenu into that popup menu. i tried the foll code but not working.

here hSubMenu and hMenu are popup menus created using CreatePopupMenu() method

LPTSTR text="details"

MENUITEMINFO mi;
mi.cbSize=sizeof(MENUITEMINFO);
mi.fMask=MIIM_FTYPE | MIIM_STRING |MIIM_ID | MIIM_CHECKMARKS|MIIM_SUBMENU ;

mi.fType=MFT_STRING;
mi.cch=lstrlen(text);
mi.hSubMenu=hSubMenu ;
mi.hbmpChecked=NULL;
mi.hbmpUnchecked=NULL;
mi.wID=id;
mi.dwTypeData=text;
InsertMenuItem(hMenu, NULL, FALSE, &mi);






Re: Visual C++ General Create Sub Menu Programmatically

Sdi

Windows-specific API questions like this belong in the appropriate Windows development forum; ask the moderator to move the post to the correct forum.



Re: Visual C++ General Create Sub Menu Programmatically

Simple Samples

Sdi wrote:
Windows-specific API questions like this belong in the appropriate Windows development forum; ask the moderator to move the post to the correct forum.

I don't know of any MSDN forum that is the correct forum that a moderator can move this to. There is a Vista forum, but technically it is supposed to be for only Vista.






Re: Visual C++ General Create Sub Menu Programmatically

crescens2k

Well, you have a few redundent things in that struct. Also, you have one problem with the string if you want it to be Unicode ready. The following is how I do things like this.

LPTSTR text = _T("Details");

MENUITEMINFO mii;

ZeroMemory(&mii, sizeof(MENUITEMINFO));

mii.cbSize = sizeof(MENUITEMINFO);

mii.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU;

mii.wID = id;

mii.hSubMenu = hSubMenu;

mii.dwTypeData = text;

mii.cch = _tcslen(text);

InsertMenuItem(hMenu, 0, FALSE, &mii);

And if you wonder. Recently I was creating a menu using manual methods for various reasons. The above is the general method I used for creating submenus and it was working.






Re: Visual C++ General Create Sub Menu Programmatically

Sdi

Have you found that any of the code in this thread fails to compile or run under Vista If so, that's a major backward-compatibility defect in Vista, and MS needs to know the details ASAP.