简体   繁体   中英

How can I intercept WndProc messages of CefSharp.WinForms.ChromiumWebBrowser?

In order to intercept the WndProc messages of the CefSharp.WinForms.ChromiumWebBrowser control I'm using a derived class so I can use Protected Overrides Sub WndProc(ByRef m As Message) .

I have two issues:

  1. I'm not receiving all messages (eg WM_MOUSEWHEEL)
  2. Clicking on the control causes a message with the value 528 (=0x210) rather than the expected 513 (= 0x201 = WM_LBUTTONDOWN).

Searching for answers I stumbled across the following SO answer ( https://stackoverflow.com/a/20489430/4247806 ) which offered an explanation and a solution, but it appears quite complicated for a task that shouldn't be that unusual. I also didn't get it working for my CEF version, (CEF 3.2454.1344.g2782fb8, Chromium 45.0.2454.101 and .net 4.5.1.).

Concrete questions would be:

  1. Why aren't all messages "forwarded"?
  2. Why is the "mouse button down message" (and others) different?

Help would, obviously, be great ;)

The answer you have linked to is basically correct, the default is to run the message loop in a different thread, which makes it difficult to receive messages. You can use a NativeWindow to hook the relevant process, see https://github.com/cefsharp/CefSharp/blob/cefsharp/47/CefSharp.WinForms.Example/ChromeWidgetMessageInterceptor.cs#L22 for an example. Download the source to see it in action.

The other option is to use the existing WinForms message loop, see https://github.com/cefsharp/CefSharp/commit/fe11f2eada542f49e4eef0feed9b2b0978446bbf#diff-f142d024925e73816b0fabd620d2f71d for an example (Download the source code and step through if you have trouble following which pieces need to be set).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM