Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

How to override Render's wndProc

User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to override Render's wndProc

Post by salvadordf »

Have you tried adding an Application.OnMessage event to the subprocess where GlobalCEFApp.ProcessType is ptRenderer ?
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to override Render's wndProc

Post by salvadordf »

I'm sorry. :oops:

I totally forgot that subprocesses don't execute "Application.Run" and you can't use the Application.OnMessage to intercept all the messages sent to that process.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to override Render's wndProc

Post by salvadordf »

The easiest way to intercept all those messages is to use the OSR mode.

In normal mode you can create a hook with SetWindowsHookEx to intercept mouse or keyboard messages :
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

I don't know the Blink implementation details and I don't know why your WndProc relacement has some problems.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to override Render's wndProc

Post by salvadordf »

I've never replaced a WndProc before but remember that you are replacing a WndProc from a different process.
Perhaps the reason why it has problems with events is that the old WndProc points to a function in a different process address space.

https://gopherproxy.meulie.net/sdf.org/ ... /ch22b.htm
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to override Render's wndProc

Post by salvadordf »

Winexcel wrote: Tue Mar 13, 2018 2:21 pm
In normal mode you can create a hook with SetWindowsHookEx to intercept mouse or keyboard messages :
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Thanks for the advice but the hook isn't a good solution because it required a very high perfomance.
I use one in BriskBard to handle the web browser zoom when the user clicks control and moves the wheel mouse button.
There's no problem if you just send a custom message with all the information to your form and return immediately after that.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to override Render's wndProc

Post by salvadordf »

It's a low level mouse hook (WH_MOUSE_LL) and it needs to be global to receive the mouse messages for different processes.

This solution has been suggested several times in the official CEF forum to receive the missing mouse and keyboard events.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to override Render's wndProc

Post by salvadordf »

Winexcel wrote: Tue Mar 13, 2018 4:31 pm I think It may call unexpected erros. But if I only send a message there, maybe, it will work well. Honestly, I don't know, but all these functions can be debugged, i mean wndProcBrowser, wndProcWidget, wndProcRender. But why? I don't understand it completely, if it's a different process i can't debug it from delphi debugger, isn't it?
All these functions is called by CrBrowserMain thread.
If I understood it correctly, SetWindowLongPtr returns the old WndProc address but that address is meaningless if it comes from a different process address space.

The author in the last link states that it's still possible to do this by "injecting" a DLL into a process's address space but I wouldn't be surprised if this is seen as a threat by antivirus software.

I think it's much easier to use a simple hook.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to override Render's wndProc

Post by salvadordf »

You were right!

Reading your posts more carefully I realized I was talking about the render process when you were talking about the message loops in some components created by the CEF libraries.

I'll see if I can add your code to TChromium and TFMXChromium. This could be used to expose "OnMessage" events! :D
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to override Render's wndProc

Post by salvadordf »

Hi,

There are many code examples in Internet. Just search "delphi setwindowshookex example" and you will find examples like these :

http://lazplanet.blogspot.com/2016/06/h ... -your.html
http://www.delphipages.com/forum/showthread.php?t=32700

When you detect a mouse wheel event you can send a custom message to your app to call TChromium.IncZoomStep or TChromium.DecZoomStep
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to override Render's wndProc

Post by salvadordf »

I use it from a thread and I try to process the messages as fast as I can to call CallNextHookEx before the OS thinks that my app is not responding fast enough and removes my hook from the chain.

Read this :
https://docs.microsoft.com/en-us/window ... nmsg/hooks
https://docs.microsoft.com/en-us/window ... owshookexw
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Post Reply