息处理函数名)
(2)声明消息处理函数
函数名称和参数必须和MESSAGE_HANDLER宏定义的一样
(3)实现消息处理函数
与一般类函数差不多
,只是在最后加上一条语句
,完成VCL对消息的默认处理
TForm::Dispatch(&Message);
消息映射
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
//自定义消息映射函数
void __fastcall WMGetMinMaxInfo(TWMGetMinMaxInfo &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_GETMINMAXINFO,TWMGetMinMaxInfo,WMGetMinMaxInfo)
END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
#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::WMGetMinMaxInfo(TWMGetMinMaxInfo &Msg)
{
//当用户单击窗体状态栏上的最大化按钮时,限制窗体的长宽
Msg.MinMaxInfo->ptMaxSize.x = 600;
Msg.MinMaxInfo->ptMaxSize.y = 400;
//设定窗体最大化时,左上角左边为窗体当前位置
Msg.MinMaxInfo->ptMaxPosition.x = Left;
Msg.MinMaxInfo->ptMaxPosition.y = Top;
//当用户用鼠标拖动的方式改变窗体尺寸时,限制其最大值
Msg.MinMaxInfo->ptMaxTrackSize.x = 600;
Msg.MinMaxInfo->ptMaxTrackSize.y = 400;
//当用户用鼠标拖动的方式改变窗体尺寸时,限制其最小值
Msg.MinMaxInfo->ptMinTrackSize.x = 200;
Msg.MinMaxInfo->ptMinTrackSize.y = 10;
//显示当前窗体的尺寸
Label1->Caption = "Width:" + AnsiString(this->Width)+
" Height: " + AnsiString(Height);
TForm::Dispatch(&Msg);
}
三、消息映射的深入讨论
../include/vcl/sysmac.h中有消息映射的宏定义
代码
#define BEGIN_