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

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.