使用Chromium嵌入式框架覆盖鼠标

时间:2012-01-03 13:26:36

标签: google-chrome winapi mouse chromium-embedded

是否可能在文件cefclient_win.cpp

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

鼠标消息被过滤掉,因为我只通过?

获得WM_MOUSEMOVE消息

似乎在WndProc获取它们之前处理左或右点击。如何禁用鼠标右键?

2 个答案:

答案 0 :(得分:2)

我解决它的方法是在CEF为每个浏览器窗口创建的线程中添加一个鼠标钩子:

// Hook to disable right mouse clicks
LRESULT CALLBACK MyMouseHook(int nCode, WPARAM wp, LPARAM lp)
{
    MOUSEHOOKSTRUCT *pmh = (MOUSEHOOKSTRUCT *) lp;

    if (nCode >= 0) {
        if( wp == WM_RBUTTONDOWN || wp == WM_RBUTTONUP ) {
            return 1;
        }
    }
    return CallNextHookEx(NULL, nCode, wp, lp);   
}

void 
CefBrowserApplication::OnCreate( 
    CefRefPtr<CefBrowserClientHandler> aBrowserClient)
{
    // Hook the mouse
    DWORD threadId = GetWindowThreadProcessId(aBrowserClient->GetBrowser()->GetWindowHandle(), NULL);
    HHOOK hook = SetWindowsHookEx(WH_MOUSE, MyMouseHook, NULL, threadId);
}

请注意,我没有使用低级鼠标挂钩,因为它们对于整个桌面来说都是全局的。在全局低级别挂钩中禁用鼠标右键将禁用所有正在运行的应用程序。

答案 1 :(得分:1)

问题是CEF创建了一个子窗口并且没有将鼠标事件传递给父窗口。我通过安装低级鼠标钩来克服它

/////////////////
// Low-level mouse hook:
//
LRESULT CALLBACK MyMouseHookLL(int nCode, WPARAM wp, LPARAM lp)
{
   MSLLHOOKSTRUCT *pmh = (MSLLHOOKSTRUCT *) lp;

    if (nCode==HC_ACTION) {
        if( wp == WM_RBUTTONDOWN || wp == WM_RBUTTONUP ) {
            //gooble it
            return 1;
        }
    }
    return CallNextHookEx(g_hHookMouseLL, nCode, wp, lp);   
}

g_hHookMouseLL = SetWindowsHookEx(WH_MOUSE_LL, MyMouseHookLL, hInst, 0);