如何检测鼠标离开窗体范围,在线

mib3000 2003-12-22 11:26:32
如题
...全文
68 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
mib3000 2003-12-22
  • 打赏
  • 举报
回复
应该在什么事件写才行,当鼠标离开窗体范围后Form的OnMouseMove就无效了阿
internetcsdn 2003-12-22
  • 打赏
  • 举报
回复
UP
mib3000 2003-12-22
  • 打赏
  • 举报
回复
cobi(我是小新)

好像只能检测到鼠标在窗体内啊,应该怎样写啊
cobi 2003-12-22
  • 打赏
  • 举报
回复
用这个判断:WindowFromPoint(Mouse.CursorPos) = Handle
qiaolin53 2003-12-22
  • 打赏
  • 举报
回复
在OnMouseMove中
if pixels(X,Y)==-1 then
begin
showmessage('不在窗口内')
end;
mib3000 2003-12-22
  • 打赏
  • 举报
回复
self.up
mib3000 2003-12-22
  • 打赏
  • 举报
回复
劳烦各位大驾,慢慢研究,不明白再请教,现在结贴
DelphiBird 2003-12-22
  • 打赏
  • 举报
回复
加个定时器,然后在定时器中监测,也就是ontimer事件
procedure TFrmMain.Timer1Timer(Sender: TObject);
var
ptMousePos : TPOINT;
begin
ptMousePos.x := 0;
ptMousePos.y := 0;
if (GetCursorPos(ptMousePos)) then
begin
if (left>ptmousepos.X) or(top>ptmousepos.y) or (left+self.Width<ptmousepos.X) or (top+self.Height<ptmousepos.Y ) then
begin
...........做你想做的事情
end;
end;



end;
Allanlove 2003-12-22
  • 打赏
  • 举报
回复
unit Unit1;

interface

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

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
function LowLevelKeyboardFunc(nCode: Integer; wParam: WPARAM; lParam: LPARAM):
LRESULT; stdcall;
const WH_MOUSE_LL=14;
var
Form1: TForm1;
hkNTKeyboard: HHOOK;

implementation

{$R *.dfm}

{ TForm1 }
function LowLevelKeyboardFunc(nCode: Integer; wParam: WPARAM; lParam: LPARAM):
LRESULT; stdcall;
var
p:Tpoint;
i,j:integer;
begin
if ncode<>0 then
begin
Result:=CallNextHookEx(0, nCode, wParam, lParam);
exit;
end;
if wParam =WM_MOUSEMOVE then
begin
Getcursorpos(p);
if (p.x< form1.left) or (p.y<form1.top) or (p.x>form1.left+form1.width) or(p.y>form1.top +form1.height) then
form1.Color:=clred
else
form1.Color:=clwindow;
end;
Result:=CallNextHookEx(0, nCode, wParam, lParam);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
hkNTKeyboard:=SetWindowsHookEx(WH_MOUSE_LL, LowLevelKeyboardFunc, HInstance, 0);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnHookWindowsHookEx(hkNTKeyboard);
end;

end.
h_x_k 2003-12-22
  • 打赏
  • 举报
回复
+一个TIMER

GetCursorPos

ClientToScreen

ScreenToClient
mib3000 2003-12-22
  • 打赏
  • 举报
回复
up

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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