i have these code for show popupmenus:

case WM_USER + 1:
                {
                    if(lParam==WM_RBUTTONUP)
                    {
                        POINT pCursor;
                        GetCursorPos(&pCursor);
                        HMENU test=GetSubMenu(GetMenu(HandleWindow),0);
                        SetForegroundWindow(HandleWindow);
                        TrackPopupMenu(test, TPM_LEFTBUTTON | TPM_RIGHTALIGN, pCursor.x, pCursor.y, 0, HandleWindow, NULL);
                        PostMessage(HandleWindow, WM_NULL, 0, 0);
                    }
                }
                break;

the menu is showed normaly, but why the click message isn't working?
heres the message loop that works normaly:

WPARAM MessageLoop()
{
    MSG msgEvents;
    while(GetMessage(&msgEvents, NULL, 0, 0) > 0)
    {
        if(IsChild(GetForegroundWindow(),msgEvents.hwnd)==TRUE || GetForegroundWindow()==msgEvents.hwnd)
        {
            if(IsDialogMessage(GetForegroundWindow(), &msgEvents) == TRUE)
            {
                 TranslateMessage(&msgEvents);
                 DispatchMessage(&msgEvents);
            }
        }
    }
    return msgEvents.wParam;
}

the menus are using the notification style:

//for get the menu click event
                //i'm using menu notifications
                case WM_MENUCOMMAND:
                {
                    MENUITEMINFO menuInfo;
                    menuInfo.cbSize = sizeof(MENUITEMINFO);
                    menuInfo.fMask=MIIM_DATA;
                    if(GetMenuItemInfo((HMENU)lParam,(UINT) wParam, true, &menuInfo )!=0)
                    {
                        Menu *mMenu = (Menu *) menuInfo.dwItemData;
                        if(mMenu!=NULL)
                            mMenu->Click();
                    }
                    menuhandle=NULL;
                }
                break;

so why, when i show the menu, the click events aren't working?
strange the mouse leave\enter are working:

//when the mouse move, enter, leave and leave the menu
                case WM_MENUSELECT:
                {
                    static int Last_Menu_ID = -1;
                    if(((HIWORD(wParam) & MF_HILITE) || (HIWORD(wParam) & MF_MOUSESELECT)) && GetMenuState((HMENU)lParam,LOWORD(wParam),MF_BYCOMMAND)!=0xFFFFFFFF)
                    {
                        //mouse leave the previous menu item
                        if(GetMenuState((HMENU)lParam,Last_Menu_ID,MF_BYCOMMAND)!=0xFFFFFFFF)
                        {
                            MENUITEMINFO menuInfo;
                            menuInfo.cbSize = sizeof(MENUITEMINFO);
                            menuInfo.fMask=MIIM_DATA;
                            GetMenuItemInfo((HMENU)lParam,Last_Menu_ID, FALSE, &menuInfo );
                            Menu *mMenu = (Menu *) menuInfo.dwItemData;
                            if (mMenu!=NULL)
                            {
                                mMenu->Leave();
                            }
                        }
                        //Mouse Enter on actual menu item
                        MENUITEMINFO menuInfo1;
                        menuInfo1.cbSize = sizeof(MENUITEMINFO);
                        menuInfo1.fMask=MIIM_DATA;
                        GetMenuItemInfo((HMENU)lParam,LOWORD(wParam), FALSE, &menuInfo1 );
                        Menu *mMenu = (Menu *) menuInfo1.dwItemData;
                        if (mMenu!=NULL)
                        {
                            mMenu->Enter();
                        }
                        Last_Menu_ID = LOWORD(wParam);
                    }
                    //testing if the menu item is valid and the Last_Menu_ID isn't -1
                    else if(GetMenuState((HMENU)lParam,LOWORD(wParam),MF_BYCOMMAND)==0xFFFFFFFF && Last_Menu_ID != -1 )
                    {
                        //mouse live the menu
                        MENUITEMINFO menuInfo;
                        menuInfo.cbSize = sizeof(MENUITEMINFO);
                        menuInfo.fMask=MIIM_DATA;
                        GetMenuItemInfo(menuhandle,Last_Menu_ID, FALSE, &menuInfo );
                        Menu *mMenu = (Menu *) menuInfo.dwItemData;
                        if (mMenu!=NULL)
                        {
                            mMenu->Leave();
                        }
                        Last_Menu_ID = -1;
                    }
                    return DefWindowProc(HandleWindow, msg, wParam, lParam);
                }
                break;

my message loop is wrong:

//Message Loop
WPARAM MessageLoop()
{
    MSG msgEvents;
    while(GetMessage(&msgEvents, NULL, 0, 0) > 0)
    {
        if(IsChild(GetForegroundWindow(),msgEvents.hwnd)==TRUE || GetForegroundWindow()==msgEvents.hwnd)
        {
            if (!IsDialogMessage(GetForegroundWindow(), &msgEvents))
            {
               TranslateMessage(&msgEvents);
               DispatchMessage(&msgEvents);
            }
        }
    }
    return msgEvents.wParam;
}

when i change the menu style with MENUINFO structure and must do, too, for submenus:

 MENUINFO mnInfo;
        mnInfo.cbSize=sizeof(MENUINFO);
        mnInfo.fMask=MIM_STYLE;
        if(systmenu==false)
            GetMenuInfo(GetMenu(MainHWND),&mnInfo);
        else
            GetMenuInfo(GetSystemMenu(MainHWND,false),&mnInfo);
        mnInfo.cbSize=sizeof(MENUINFO);
        mnInfo.fMask=MIM_STYLE | MIM_APPLYTOSUBMENUS;
        mnInfo.dwStyle=MNS_NOTIFYBYPOS;
        if(systmenu==false)
            SetMenuInfo(GetMenu(MainHWND),&mnInfo);
        else
            SetMenuInfo(GetSystemMenu(MainHWND,false),&mnInfo);

now the menu commands works on menu context's.
thanks to all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.