I create a context menu like this:
Re开发者_高级运维source file:
IDR_CONTEXT MENU
BEGIN
POPUP ""
BEGIN
MENUITEM "Add &last", ID_ADDLAST
MENUITEM "Add &before", ID_ADDBEFORE
MENUITEM "Add &after", ID_ADDAFTER
MENUITEM "&Remove", ID_REMOVE
END
END
And the window procedure:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_RBUTTONDOWN:
{
POINT cursor;
GetCursorPos(&cursor);
TrackPopupMenu((HMENU) GetSubMenu(LoadMenu(hInstance, MAKEINTRESOURCE(IDR_CONTEXT)), 0), TPM_LEFTALIGN, cursor.x, cursor.y, 0, hWnd, NULL);
}
break;
}
}
But this doesn't allow me to right click on the items in the context menu. I can only left click on them... How to fix this?
If you read the documentation page for TrackPopupMenu
, you will find a flag described as "The user can select menu items with both the left and right mouse buttons."
精彩评论