是我前不久问的一个帖子,功能都实现了,可是客户变态,还要来点"花"的.
以下是我的初步尝试.
怎样实现类似qq的窗口顶部停靠效果?
当窗体在屏幕上方某个区域时,窗体上移,只留一小部分在屏幕显示
当鼠标移入这一小部分的时候,窗体下移
当鼠标移出时,窗体又上移.
我想了一下:主要有两个技术点:
1:怎么得到窗体的移动结束事件?我想应该是截获WM_MOVE消息
2:怎么得到鼠标移入,移出窗体的事件,我想应该可以用到
CM_MOUSEENTER,CM_MOUSELEAVE消息
下面是我初步实现的效果:
Unit1.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
TEdit *Edit1;
private: // User declarations
bool in; //标识鼠标是否进入窗体
void __fastcall MouseEnter(Messages::TMessage &Message);
void __fastcall MouseLeave(Messages::TMessage &Message);
void __fastcall FormMoveEnd(Messages::TMessage &Message);
public: // User declarations
__fastcall TForm1(TComponent* Owner);
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(CM_MOUSEENTER,Messages::TMessage,MouseEnter)
VCL_MESSAGE_HANDLER(CM_MOUSELEAVE,Messages::TMessage,MouseLeave)
VCL_MESSAGE_HANDLER(WM_MOVE,Messages::TMessage,FormMoveEnd)
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)
{
in = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MouseEnter(Messages::TMessage &Message)
{
if(in)
exit;
in = true;
Edit1->Text = "enter";
if(Form1->Top < 0)
Form1->Top = 10;
}
void __fastcall TForm1::MouseLeave(Messages::TMessage &Message)
{
in = false;
Edit1->Text = "leave";
if(Form1->Top == 10)
{
Form1->Top = -(Form1->Height -15);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMoveEnd(Messages::TMessage &Message)
{
if(Form1->Top < 10)
{
Form1->Top = -(Form1->Height - 15);
}
}
以上程序初步实现了类似效果.但有点问题,就是我的鼠标移动到屏幕最上方时候,窗体会不间断的闪烁.
好像是连续激发了鼠标离开窗体和进入窗体的事件.
有点苦恼,请高手指点一下