鼠标离开窗体时……

hubao 2002-10-18 05:44:55
屏幕上有多个FORM ,当鼠标离开窗体时能够自动隐藏。要怎么做啊 ?
...全文
50 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hubao 2002-10-18
  • 打赏
  • 举报
回复
不能有按扭啊
hubao 2002-10-18
  • 打赏
  • 举报
回复
只出来in
zbc 2002-10-18
  • 打赏
  • 举报
回复
第二种是处理Screen的事件
Screen->OnActiveFormChange = ChangeForm;
上面的意思是调用你自己所定义的函数,我现在代码写的有一点乱,你看看行不?
.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormPaint(TObject *Sender);
private: // User declarations
public: // User declarations
void __fastcall ChangeForm(TObject *Sender);
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ChangeForm(TObject *Sender)
{
this->Hide();
Screen->ActiveForm->Caption = "这是被激活的窗体";
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TForm2 *Form2 = new TForm2(Application);
Form2->ShowModal();
delete Form2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
Screen->OnActiveFormChange = ChangeForm;
}
//---------------------------------------------------------------------------
zbc 2002-10-18
  • 打赏
  • 举报
回复
给你两种实现方法,这是第一种,第二种等一下:)
.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#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
public: // User declarations
virtual void __fastcall WndProc(TMessage &message);
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
.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::WndProc(TMessage &message)
{
if(message.Msg == CM_MOUSEENTER)
Caption = "in";
if (message.Msg == CM_MOUSELEAVE)
Caption = "out";
TForm::WndProc(message);
}
everandforever 2002-10-18
  • 打赏
  • 举报
回复
调用 _TrackMouseEvent() 函数以获得 WM_MOUSELEAVE 消息.
响应这个消息就可以了.

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧