Midas
Midas

Reputation: 7131

Right clicking in WinAPI context menu

I create a context menu like this:

Resource 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?

Upvotes: 1

Views: 3401

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283624

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."

Upvotes: 2

Related Questions