CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [RESOLVED] {win32] - how make the context menu corresponding to messages?

    i have these code for show the context menu:
    Code:
    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);
    the context menu is showed without a problem. but when i click on menu items, nothing happens... why?
    (i use WM_MENUCOMMAND message, because i use the menu notifications)
    heres my message loop function(but works fine):
    Code:
    //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) == TRUE)
                {
                     TranslateMessage(&msgEvents);
                     DispatchMessage(&msgEvents);
                }
            }
        }
        return msgEvents.wParam;
    }
    anotherthing: the WM_MENUSELECT message works normaly. unless i can, using the WM_MENUSELECT, for detect the mouse click.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: {win32] - how make the context menu corresponding to messages?

    Quote Originally Posted by Cambalinho View Post
    ...
    the context menu is showed without a problem. but when i click on menu items, nothing happens... why?
    (i use WM_MENUCOMMAND message, because i use the menu notifications)
    But how and where do you handle this WM_MENUCOMMAND message? You didn't show it in your OP.
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: {win32] - how make the context menu corresponding to messages?

    Quote Originally Posted by VictorN View Post
    But how and where do you handle this WM_MENUCOMMAND message? You didn't show it in your OP.
    sorry about that:
    Code:
    case WM_INITMENUPOPUP:
                    {
                        menuhandle=(HMENU)wParam;
                        return DefWindowProc(HandleWindow, msg, wParam, lParam);
                    }
                    break;
    
    
    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;

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: {win32] - how make the context menu corresponding to messages?

    1. Is the code under case WM_MENUCOMMAND: executed?
    2. What is the return value of GetMenuItemInfo? TRUE or FALSE?
    3. What is Menu? What is the value of mMenu? Isn't it NULL?
    4. What does the
    Code:
         mMenu->Click();
    do? Is it executed?

    IOW, did you debug your code or, as usual, you are trying to let the Forum do your job?
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    Re: {win32] - how make the context menu corresponding to messages?

    Quote Originally Posted by VictorN View Post
    1. Is the code under case WM_MENUCOMMAND: executed?
    2. What is the return value of GetMenuItemInfo? TRUE or FALSE?
    3. What is Menu? What is the value of mMenu? Isn't it NULL?
    4. What does the
    Code:
         mMenu->Click();
    do? Is it executed?

    IOW, did you debug your code or, as usual, you are trying to let the Forum do your job?
    if i click on menu item, on menu bar, the Click lambda is executed, the problem is only on menu context

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: {win32] - how make the context menu corresponding to messages?

    Quote Originally Posted by Cambalinho View Post
    if i click on menu item, on menu bar, the Click lambda is executed, the problem is only on menu context
    I put four questions trying to help you.
    And you did not answer any.
    So what help do you consider?
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2009
    Posts
    1,355

    Re: {win32] - how make the context menu corresponding to messages?

    i tested now, the WM_MENUCOMMAND, on menu context, isn't executed

  8. #8
    Join Date
    Apr 2009
    Posts
    1,355

    Re: {win32] - how make the context menu corresponding to messages?

    tested: the WM_COMMAND is executed. why if the menu item style is notification?

  9. #9
    Join Date
    Apr 2009
    Posts
    1,355

    Re: {win32] - how make the context menu corresponding to messages?

    anotherthing form msdn: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    "
    Menus

    If an application enables a menu separator, the system sends a WM_COMMAND message with the low-word of the wParam parameter set to zero when the user selects the separator.
    If a menu is defined with a MENUINFO.dwStyle value of MNS_NOTIFYBYPOS, WM_MENUCOMMAND is sent instead of WM_COMMAND."

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: {win32] - how make the context menu corresponding to messages?

    Quote Originally Posted by Cambalinho View Post
    tested: the WM_COMMAND is executed. why if the menu item style is notification?
    What is "notification"? Do you mean MNS_NOTIFYBYPOS style? Where and how do you set it for the menu?

    BTW, what is the reason to handle WM_MENUCOMMAND rather than WM_COMMAND message?
    Victor Nijegorodov

  11. #11
    Join Date
    Apr 2009
    Posts
    1,355

    Re: {win32] - how make the context menu corresponding to messages?

    when i create the menu items:
    Code:
    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;
            mnInfo.dwStyle=MNS_NOTIFYBYPOS;
            if(systmenu==false)
                SetMenuInfo(GetMenu(MainHWND),&mnInfo);
            else
                SetMenuInfo(GetSystemMenu(MainHWND,false),&mnInfo);
    but you give me the help that i need
    thanks for all
    Code:
    case WM_COMMAND:
                    {
                        if(HIWORD(wParam)==0)
                        {
                            if (GetMenuState((HMENU)menuhandle,(UINT)LOWORD(wParam),MF_BYCOMMAND)!=0xFFFFFFFF )
                            {
                                MENUITEMINFO menuInfo;
                                menuInfo.cbSize = sizeof(MENUITEMINFO);
                                menuInfo.fMask=MIIM_DATA;
    
                                GetMenuItemInfo(menuhandle,(UINT) LOWORD(wParam), FALSE, &menuInfo );
    
                                Menu *mMenu = (Menu *) menuInfo.dwItemData;
                                if (mMenu!=NULL)
                                {
                                    mMenu->Click();
                                }
                            }
                        }
    
                        SendMessage((HWND)lParam , WM_COMMAND, wParam, lParam);
                        return DefWindowProc(HandleWindow, msg, wParam, lParam);
                    }
                    break;
    the WM_COMMAND, seems, don't give me the HMENU item, but i have it with WM_INITMENUPOPUP message. and now works fine. but i continue confused why these happens

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: {win32] - how make the context menu corresponding to messages?

    Quote Originally Posted by Cambalinho View Post
    when i create the menu items:
    ...
    the WM_COMMAND, seems, don't give me the HMENU item, but i have it with WM_INITMENUPOPUP message. and now works fine. but i continue confused why these happens
    I never used/handled WM_MENUCOMMAND, so can only guess.
    What you you would add MIM_APPLYTOSUBMENUS flag to the menu mask?
    Code:
    MENUINFO mnInfo;
            mnInfo.cbSize=sizeof(MENUINFO);
            mnInfo.fMask=MIM_STYLE | MIM_APPLYTOSUBMENUS;
    Victor Nijegorodov

  13. #13
    Join Date
    Apr 2009
    Posts
    1,355

    Re: {win32] - how make the context menu corresponding to messages?

    Quote Originally Posted by VictorN View Post
    I never used/handled WM_MENUCOMMAND, so can only guess.
    What you you would add MIM_APPLYTOSUBMENUS flag to the menu mask?
    Code:
    MENUINFO mnInfo;
            mnInfo.cbSize=sizeof(MENUINFO);
            mnInfo.fMask=MIM_STYLE | MIM_APPLYTOSUBMENUS;
    i have another diferent error too.. but you have 100% right. thanks for all
    now works fine

  14. #14
    Join Date
    Apr 2009
    Posts
    1,355

    Re: {win32] - how make the context menu corresponding to messages?

    and the other error was fixed too
    thanks for all

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: [RESOLVED] {win32] - how make the context menu corresponding to messages?

    You are welcome!
    Victor Nijegorodov

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured