WINAPI捕获鼠标右键

时间:2015-03-17 16:20:52

标签: c++ winapi switch-statement mouseevent

我在捕获鼠标点击时遇到问题。我要处理案件:

-WM_NCHITTEST拖放窗口(捕获点击并保持)

-WM_RBUTTONDOWN,这是一个右键单击的conext菜单

我不知道如何将这两者结合起来,以便它们都能正常工作。目前,只有NCHITEST工作 - 它需要所有点击。从未输入RBUTTONDOWN。对此有何帮助?

case WM_NCHITTEST:  
        {  //Function used from MSDN
            POINT p = { LOWORD(lParam), HIWORD(lParam) };  
            ::ScreenToClient(hWnd, &p);  

            RECT r;  
            GetClientRect(hWnd, &r);  

                return PtInRect(&r, p) ? HTCAPTION : DefWindowProc(hWnd, message, wParam, lParam);  
            }
break;

case WM_RBUTTONDOWN:
    KillTimer(ball, ID_TIMER);
    p.x = LOWORD(lParam);
    p.y = HIWORD(lParam);
    hPopupMenu = CreatePopupMenu();
    ClientToScreen(hWnd, &p);

    AppendMenuW(hPopupMenu, MF_STRING, IDM_EXIT, L"EXIT");
    InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, IDM_EXIT, TEXT("Color Picker"));
    SetForegroundWindow(hWnd);
    TrackPopupMenu(hPopupMenu, TPM_RIGHTBUTTON | TPM_BOTTOMALIGN | TPM_LEFTALIGN, p.x, p.y, 0, hWnd, NULL);
    DestroyMenu(hPopupMenu);
    SetTimer(ball, ID_TIMER, 1, NULL);
    break;

1 个答案:

答案 0 :(得分:0)

也许你可以处理WM_NCRBUTTONDOWN

case WM_NCRBUTTONDOWN: {
    if(wParam==HTCAPTION) {
        TrackPopupMenu(hMenu,TPM_LEFTALIGN|TPM_RIGHTBUTTON,GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam),0,hWnd,NULL);
    }
    break;
}