Override mouse using Chromium embedded framework

Is it possible that in file cefclient_win.cpp

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

mouse messages are filtered out, as I only get WM_MOUSEMOVE message through?

It seems like left or right clicks are handled before the WndProc gets a hold of them. How do I disable right mouse click in particular?

Answers


The way I solved it was by adding a mouse hook to the thread created by CEF for each browser window:

// 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);
}

Note that I'm not using a low level mouse hook, since those are global for the entire desktop. Disabling right mouse clicks in a global low level hook would disable it for all running applications.


The problem is that CEF creates a child window and doesnt pass mouse events to parent. I overcame it by installing Low Level Mouse Hook

/////////////////
// 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);

Need Your Help