欢迎来到天天文库
浏览记录
ID:46496829
大小:96.50 KB
页数:21页
时间:2019-11-24
《C++builder消息的运用》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C卄builder消息的运用一、TApplication的OnMessage事件OnMcssagc事件只处理消息队列中的消息,ScndMcssagc()发送的消息不会被截获。任何窗体接收到一个windows消息,都会触发一次此事件函数原型:typedefvoid—fastcal1(__closure^TMessageEvent)(tagMSG&Msg,bool&Handled);Msg表示被截获的消息,Handled表示是否处理完成,为TRUE则防止被再次处理,设为FALSE则可以继续处理。代码//计算程序响应的消息数//#if
2、ndefMsg_testH#defineMsg_testH//ttinclude〈Classes.hpp>#inelude〈Controls.hpp>itincludc#inelude//classTForml:publicTForm{_published://IDE-managedComponentsTLabel*Labell;void_fastcal1FormCreate(TObject*Sender);private://Userdeclarations//口定义消息响应函
3、数void―fastcallAppMessage(tagMSG&MSG,bool&Handled);public://Userdeclarations_fastcallTForml(TComponent*Owner);intNum;};//externPACKAGETForml*Forml;//ttendif//Winclude^pragmahdrstop#inelude〃Msg_test.h〃//^pragmapackage(smartinit)^pragmaresource〃*.dfnTTForml*Forml
4、;//_fastcallTForml::TForml(TComponent*Owner):TForm(Owner){Num=0;)//void_fastcallTForml::FormCrcatc(TObjcct*Scndcr){//将口定义函数与OnMessage事件联系起來Application-〉0nMessage二AppMessage;//void_fastcallTForml::AppMessage(tagMSG&MSG,bool&Handled)Num++;Labell~>Caption二AnsiString(Num
5、);Ilandied=false;)二、消息映射使用消息映射,一般需要三步:(1)•声明消息映射表,把某些消息的处理权,交给自C定义的函数以一个没有参数的BEGINMESSAGE,MAP宏开始,以END_MESSAGE_MAP宏结束(唯一参数是组件的父类的名字,通常为TForm)在中间插入一个或多个MESSAGE_HANDLER宏,其将一个消息句柄和一个消息处理函数联系在一起。MESSAGEJIANDLER(windows消息名,消息结构体名,消息处理函数名)(2)声明消息处理函数函数名称和参数必须和MESSAGE_HANDLE
6、R宏定义的一样(3)实现消息处理函数与一般类函数井不多,只是在最后加上一条语句,完成VCL对消息的默认处理TForm::Dispatch(&Mcssagc);消息映射//#ifndefUnitlH#defineUnitlH//ttincludc〈Classes.hpp>ttinclude^includettinclude//classTForml:publicTForm{__ublished://IDE-meinagedComponentsTLabcl
7、*Labell;private://Userdeclarationspublic://Userdeclarations_fastcallTForml(TComponent*Owner);//自定义消息映射函数voidfastcallWMGetMinMaxInfo(TWMGctMinMaxInfo&Msg);BEGIN_MESSAGE_MAPMESSAGE_HANDLER(WM_GETMTNMAXTNFO,TWMGetMinMaxInfo,WMGetMinMaxInfo)END_MESSAGE_MAP(TForm)//extern
8、PACKAGETForml*Forml;//#endif//★includettpragmahdrstopttinclude"Unitl.h"//ttpragmapackage(smart_inil)^pragmaresource〃*.dfm〃TF
此文档下载收益归作者所有