In Delphi, sometimes we want the object to be able to receive Windows messages. Because you want to receive Windows messages at least with Windows Handle, do you want to create a visible window? That seems too passable. Delphi provides a function Classes.allocatehwnd. Analysis Allocatehwnd found Delphi CreateWindowEx a size of 0 window, the window is generated, handle also have, but the window message to deal with it, otherwise how to let the object receive Windows message it, But we all know that the class function is not the same as the Windows message handler, and the address of the class function should be the offset of the self+ function. This Delphi also help us to deal with, in the Allocatehwnd of our incoming object function through makeobjectinstance into a normal function, and then we can process the object inside the Windows message.
The shorthand code is as follows:
Tmyhandlewinmessage = Class
Private
Fwinhandle:hwnd;
Procedure WndProc (var msg:tmessage);
Public
Constructor Create;
destructor Destroy; Override
End
Create implementation:
Fwinhandle = Classes.allocatehwnd (WndProc);
Destroy implementation:
If Fwinhandle <> 0 then Classes.deallocatehwnd (fwinhandle); System core objects must be released
WndProc implementation:
Deal with the messages you are interested in here, or hand it over to Windows.
With MSG do
If MSG = XXX then//message you intend to process
Begin
//
End
Else
Result: = DefWindowProc (Fwinhandle, MSG, WParam, LParam);
http://blog.csdn.net/shandiantianying/article/details/9786425
Delphi uses the generic class object to create an accept window message (using Classes.allocatehwnd to create a Windows with size 0 for the object, with handle) good