I am using vc6.0. I load a popmenu when right click to a listbox item. But it seems not send WM_COMMAND message when I click the popmenu item. I dont have any clue about this after seaching in google. Does anyone knows?
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);
}
}
}
}
}
Not get Message Box at code below.
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;
}
}
Solved. Found it on 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.
I set hwnd
as listbox not the dialog.