Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 815
Ulterior Avatar asked Jan 24 '26 12:01

Ulterior


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

like image 89
Fredrik Allansson Avatar answered Jan 26 '26 23:01

Fredrik Allansson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!