i did these menu class:
class Menu
{
private:
static int intID;
int ID=0;
bool primeiromenu=false;
HMENU MenuHandle=NULL;
HMENU hMenu=NULL;
int menuposition=0;
string strCaption="";
public:
Menu(string caption="&Menu",HMENU subtmenu=NULL, HWND MainHWND=WindowMain)
{
intID=intID+1;
ID=intID;
if(caption!="-")
caption=(string)caption + " " + to_string(ID);
strCaption=caption;
if(GetMenu(MainHWND)==NULL)
hMenu = CreateMenu();
else
hMenu =GetMenu(MainHWND);
if (subtmenu==NULL)
{
HMENU hSubMenu=CreatePopupMenu() ;
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, caption.c_str());
MenuHandle=hSubMenu;//my error was here
SetMenu(MainHWND, hMenu);
menuposition=GetMenuItemCount(hMenu)-1;
primeiromenu=true;
}
else
{
if(caption=="-")
AppendMenu(subtmenu, MF_SEPARATOR, ID, caption.c_str());
else
AppendMenu(subtmenu, MF_STRING, ID, caption.c_str());
MenuHandle=subtmenu;
menuposition=GetMenuItemCount(subtmenu)-1;
SetMenu(MainHWND, hMenu);
}
}
void Show(HWND mainshowed)
{
LPPOINT x;
GetCursorPos(x);
SetForegroundWindow(mainshowed);
TrackPopupMenu(MenuHandle,NULL,x->x,x->y,0,mainshowed,NULL);
PostMessage(mainshowed, WM_NULL, 0, 0);
}
int getmenuposition()
{
return menuposition;
}
property<string> Caption
{
Get(string)
{
return strCaption;
},
Set(string text)
{
MENUITEMINFO mi;
mi.cbSize=sizeof(MENUITEMINFO);
if(primeiromenu==true)
GetMenuItemInfo(GetMenu(WindowMain),menuposition,true,&mi);
else
GetMenuItemInfo(MenuHandle,menuposition,true,&mi);
mi.fMask=MIIM_STRING;
mi.dwTypeData =(LPTSTR)text.c_str();
if(primeiromenu==true)
SetMenuItemInfo(GetMenu(WindowMain),menuposition,true,&mi);
else
SetMenuItemInfo(MenuHandle,menuposition,true,&mi);
}
};
operator int()
{
return ID;
}
operator HMENU()
{
return MenuHandle;
}
void Destroy()
{
DestroyMenu(MenuHandle);
}
};
int Menu::intID=0;
the function Show only show me the menu rectangle... and the OS close the program. what i'm doing wrong?