开发者

Right clicking in WinAPI context menu

开发者 https://www.devze.com 2023-03-06 08:26 出处:网络
I create a context menu like this: Re开发者_高级运维source file: IDR_CONTEXT MENU BEGIN POPUP \"\"

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

0

精彩评论

暂无评论...
验证码 换一张
取 消