Forum > General

Easy Message hooking for forms. UNIT and TEST PROJECT Attached.

(1/2) > >>

After seeing lots of efforts of those trying to implement unsupported message events in the Class code I decided to contribute this simple test project and MsgHook unit...

 Please rip it apart..  :)

 Currently its for windows but it should work for Linux too if you use the LCLType and LCLIntf with a some name changes.


Very nice work and very useful!
It would be great to have it integrated in LCL.
Small and efficient and also helps a lot in debugging source code based on LCL.

Using list for this is way too slow. Delphi uses MakeObjectInstance and FreeObjectInstance from Classes unit for this purpose. Their implementation is ugly, but it looks like, that it's made for max performance. Problem is - they use runtime code generation, that isn't cross-platform, I guess. I.e. platform-dependent inc file is needed.

Hi, nice, it will be very helpfull in some case, like grab keys from any where. +1  :)

I'll test it with my "HotShortcutkeys manager" component, it should be solved my cross-plateform compatibility.  ;)



--- Quote from: jamie on August 30, 2020, 12:49:52 pm ---I understand the concept isn't as fast as doing it at the raw level.

Also if all u need is a couple of msgs added the search is at the top and exits when found

If u look how the lcl is done now it uses the dispatch system and it seems to work well enough

Any ways this would be less load per class if a feature of adding mgs were put in.
Have a good day :)

--- End quote ---
There are several ways to solve this problem. Standard way - is to allocate space in window (i.e. cbWndExtra), store pointer to Form there and read it via GetWindowLong. But it requires modifying window class registration procedure. Dunno, why nobody uses it. May be because it's way too slow. Or may be because it works on Windows only. Perfect way - to generate code stub. But it's not cross-platform. Yeah, lists are cross-platform. But at least it would be better to turn list into Form->Message tree, sort lists and use binary search. May be even hashing. Hashing would be easy, as handle is used as key, i.e. it would be enough to use several most significant bits as hash value.


[0] Message Index

[#] Next page

Go to full version