懂C++builder的大富翁,请过来帮一下忙:编写的控件:如何在控件里响应window的消息? (20分)

Z

zhbruce

Unregistered / Unconfirmed
GUEST, unregistred user!
写了一个响应windows消息的控件,作用是验证一下控件里如何响应消息。
但是写好调试时,没有出现所要求的结果。。
控件正常结果:按下窗体最小化时,就会弹出一个写着“aa”的窗口。
但是调试时没有出现这个结果。
控件源码如下;
H文件:
//---------------------------------------------------------------------------

#ifndef ShowTestH
#define ShowTestH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class PACKAGE TShowTest : public TControl
{
private:
protected:
void __fastcall WmSyscommand(TMessage &Message);//处理消息的函数
BEGIN_MESSAGE_MAP//消息映象表
MESSAGE_HANDLER(WM_SYSCOMMAND,TMessage,WmSyscommand)
END_MESSAGE_MAP(TControl)
public:
__fastcall TShowTest(TComponent* Owner);
__published:
};
//---------------------------------------------------------------------------
#endif
====================================================================================================================================================
组件CPP文件:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "ShowTest.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(TShowTest *)
{
new TShowTest(NULL);
}
//---------------------------------------------------------------------------
__fastcall TShowTest::TShowTest(TComponent* Owner)
: TControl(Owner)
{
}
void __fastcall TShowTest::WmSyscommand(TMessage &Message)//处时消息函数
{
if (Message.WParam==SC_MINIMIZE)//如果按了最小化
ShowMessage("aa");//显示
}
//---------------------------------------------------------------------------
namespace Showtest
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TShowTest)};
RegisterComponents("Samples", classes, 0);
}
}
//---------------------------------------------------------------------------
====================================================================================================================================================
帮助调试的项目:
H头文件
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
TShowTest *tester;//声明对象
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
====================================================================================================================================================
CPP文件

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "ShowTest.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{ tester=new TShowTest(this);
tester->Parent=this;
}
//---------------------------------------------------------------------------
因为是测试之用,所以很简。见谅。
请问我如此的控件响应消息有没有错误。
请问错了什么地方? 令我得不到想做的结果。
谢谢各位英雄帮忙。
真是万分感激。
想了两天都没有搞掂。。
谢谢。
 
我看应该没问题,正好这里没有cb没有试一下,平常也是这么用的
只需看看:END_MESSAGE_MAP(TControl)
             ~~~~~~~~~改成TShowTest试试?
 
to sonie
是不行的,说是overflow
谢谢
 
虽然还没有解决问题。但是很感激你的帮助。
 
顶部