【问题标题】:POPUP menu not send WM_COMMAND message弹出菜单不发送 WM_COMMAND 消息
【发布时间】:2014-04-19 09:09:30
【问题描述】:

我使用的是vc6.0。右键单击列表框项目时,我会加载一个弹出菜单。但是当我单击弹出菜单项时,它似乎没有发送 WM_COMMAND 消息。在谷歌搜索后,我对此一无所知。有谁知道吗?

void PT_OnContextMenu(HWND hwnd, HWND hwndContext, UINT xPos, UINT yPos)
{
    HWND hList = GetDlgItem(hwnd,IDC_LIST_PRESTYPE);
    if (hList == hwndContext)
    {
        if(-1!=indexLB)
        {
            RECT rect;  
            POINT pt;  
            pt.x = xPos;
            pt.y = yPos;
            ListBox_GetItemRect(hwndContext, indexLB, &rect);
            ScreenToClient(hwndContext, &pt);
            if(PtInRect(&rect, pt))
            {                 
                HMENU hMenu = LoadMenu((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), MAKEINTRESOURCE(IDR_MENU_RDELTYPE));                  
                if(hMenu)  
                {  
                    HMENU hpop = GetSubMenu(hMenu,0);  
                    ClientToScreen(hwndContext, &pt);  
                    TrackPopupMenu(hpop,  
                        TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON,  
                        pt.x,  
                        pt.y,  
                        0,  
                        hwndContext,  
                        NULL);  
                    DestroyMenu(hMenu);  
                }  
            }  
        }
    }
}

在下面的代码中没有得到消息框。

void PT_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
    switch(id)
    {
        case ID_MENUITEM_RDELTYPE:
        {
            MessageBox(hwnd,TEXT("dddd!"),TEXT("dddd"),MB_OK);
        }
        break;
        default:
        break;
    }
}

【问题讨论】:

    标签: winapi visual-c++ contextmenu visual-c++-6 popupmenu


    【解决方案1】:

    解决了。在MSDN找到它

    A handle to the window that owns the shortcut menu. This window receives all messages
    from the menu. The window does not receive a WM_COMMAND message from the menu until the
    function returns. If you specify TPM_NONOTIFY in the uFlags parameter, the function does
    not send messages to the window identified by hWnd. However, you must still pass a window
    handle in hWnd. It can be any window handle from your application. 
    

    我将hwnd 设置为列表框而不是对话框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      相关资源
      最近更新 更多