如何得到鼠标移入移出窗口标题栏的事件?(100分)

  • 主题发起人 主题发起人 ismile2002
  • 开始时间 开始时间
I

ismile2002

Unregistered / Unconfirmed
GUEST, unregistred user!
如何得到鼠标移入移出窗口标题栏的事件?
 
在 form 中放一个 TEdit 就可以进行验证,以下是调试成功的代码:
//进出标题栏的捕捉
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure AppMessage(var Msg:TMsg;var Handled:Boolean);
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }
var
InCaption:Boolean=false;

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
var
Statechange:Boolean;
begin
Statechange:=false;
if Msg.message=WM_NCMOUSEMOVE then
begin
if DefWindowProc(handle,WM_NCHitTest,0,
GetMessagePos)=HTCAPTION then
begin
if not(InCaption) then Statechange:=true;
end
else
if InCaption then Statechange:=true;
//到标题栏上面的边框,也是出标题栏
end;

if Msg.message=WM_MOUSEMOVE then
if InCaption then Statechange:=true;

if statechange then
begin
InCaption:=not(InCaption);
if InCaption then Edit1.Text:='In Caption' //进入标题栏
else Edit1.Text:='Out Caption'; //从标题出来
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:=AppMessage;
end;

end.
 

Similar threads

后退
顶部