MouseEnter(マウスが来た)イベントを取得するサンプルです。
スタティックテキストの上にマウスを置いたところ スタティックテキストからマウスを離したところ
//---------------------------------------------------------------------------//----------------------------------------------------------------
// Unit1.h
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE 管理のコンポーネント
TStaticText *StaticText1;
private:
void __fastcall OnMouseEnter(TMessage & msg); // ユーザー宣言
public: // ユーザー宣言
__fastcall TForm1(TComponent* Owner);
protected:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, OnMouseEnter)
END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
// Unit1.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::OnMouseEnter(TMessage & msg)
{
if (msg.LParam == long(StaticText1)){
StaticText1->Caption = "MouseEnter";
}else{
StaticText1->Caption = "Mouseleave";
}
}
DownLoad bcbtips061.lzh 4KB(BCB5)