积累系统性知识
积聚技术精华
  首页    个人中心    撰写积文    建立课题    订立目标    整理积文    管理课题    管理目标    技能Get    代码积累 
BCB中自定义消息
error997 (error997)    2014-11-20 20:37:28      目标    课题
   在C++BUILDER中如何使用自定义消息和编写自定义消息的消息处理函数
---------------------------------------------------------------
   unit1.h
切换到: 纯代码  
   
//---------------------------------------------------------------------------
   #ifndef  Unit1H
#define  Unit1H
//---------------------------------------------------------------------------
#include  <Classes.hpp>
#include  <Controls.hpp>
#include  <StdCtrls.hpp>
#include  <Forms.hpp>
#define  WM_MYMESSAGE  WM_APP+1    //自定义消息ID
//---------------------------------------------------------------------------
class  TForm1  :  public  TForm
{
__published:            //  IDE-managed  Components
       TButton  *Button1;
       TButton  *Button2;
       void  __fastcall  Button1Click(TObject  *Sender);
       void  __fastcall  Button2Click(TObject  *Sender);
private:            //  User  declarations
       void  __fastcall  CMMessage(TMessage  &msg);    //消息接收处理函数
public:                        //  User  declarations
       __fastcall  TForm1(TComponent*  Owner);

       BEGIN_MESSAGE_MAP
切换到: 纯代码  
   
               VCL_MESSAGE_HANDLER(WM_MYMESSAGE,TMessage,CMMessage)
               //决定WM_MYMESSAGE消息交给CMMessage  函数处理
       END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern  PACKAGE  TForm1  *Form1;
//---------------------------------------------------------------------------
#endif
   

unit.cpp
切换到: 纯代码  
   
   //---------------------------------------------------------------------------
   #include  <vcl.h>
#pragma  hdrstop
   #include  "Unit1.h"
//---------------------------------------------------------------------------
#pragma  package(smart_init)
#pragma  resource  "*.dfm"
TForm1  *Form1;
//---------------------------------------------------------------------------
__fastcall  TForm1::TForm1(TComponent*  Owner)
       :  TForm(Owner)
{
}
//---------------------------------------------------------------------------
void  __fastcall  TForm1::CMMessage(TMessage  &msg)
{
         if(msg.WParam  ==  0){
               ShowMessage("haha");
         }else
         if(msg.WParam  ==  1){
               ShowMessage("xixi");
         }
}
void  __fastcall  TForm1::Button1Click(TObject  *Sender)
{
             SendMessage(Handle,WM_MYMESSAGE,1,0);  //发送消息
}
//---------------------------------------------------------------------------
   void  __fastcall  TForm1::Button2Click(TObject  *Sender)
{
             SendMessage(Handle,WM_MYMESSAGE,0,0);//发送消息
   }
//---------------------------------------------------------------------------


转自 http://blog.csdn.net/y___y/article/details/1267112
(+0)技能Get

建议楼主:搜索关键字 |参考其他资源 |回复 |追问
  error997(error997):   个人中心    课题    目标    代码积累