Message handling techniques for non-visual components of CB

Source: Internet
Author: User

A component that is not visible must respond to Windows operating systems or user-defined messages. However, because a non-visual component does not have a window, so it does not have a window handle, and naturally it cannot receive messages, in order to solve this problem, our idea is to create a hidden window so that non-visual components can receive messages.

To create a hidden window for your non-visual component, you need the following:

1. The HWND of a private variable type (private Variable) to get the window handle.

2. A function (a WndProc) that is used to capture a window sent to a component.

3. A call to Allcolatehwnd causes the window handle to be created and the WndProc is set.

In order to clearly explain the above ideas and show the creation process, we will take a concrete example to illustrate.

First we create a new component, in C + + builder, select file| NEW ... Double-click the component icon to display a new Component dialog box change ancestor type is Tcomponent and class name is TTest and set.

Then, switch to the header file for the new component and add the following declaration to the private section of the Class (private sections):

HWnd Fhandle;

void __fastcall WndProc (tmessage &msg);

The first line declares an HWND variable that invokes the Fhandle, which is used to capture the window handle after the window is created.

The second line declares a WndProc function for receiving messages. The declaration of this function must be identified to qualify it as a wndproc, and then construct the following declaration in the class declaration public (publicly) section:

Viod DoIt( );
   这个公有函数将被我们用来测试组件,类声明应如下:
   class PACKAGE Ttest:public Tcomponent
    {
    private:
     HWnd Fhandle;
     void __fastcall WndProc(Tmessage &Msg);
    protected:
    public:
     __fastcall Ttest(Tcomponent *Owner);
     void DoIt( );
    __published:
    };

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.