我正在使用vc6.0。右键单击列表框项时,我加载了一个popmenu。但是当我点击popmenu项时似乎没有发送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;
}
}
答案 0 :(得分:2)
解决。在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
设置为列表框而非对话框。