****有关MOUSE移动的问题**** ( 积分: 50 )

  • 主题发起人 主题发起人 lovelovelily
  • 开始时间 开始时间
L

lovelovelily

Unregistered / Unconfirmed
GUEST, unregistred user!
请问想做一个窗体随MOUSE移动的程序;
当MOUSE移到屏幕最右边时,该窗体显示在MOUSE的左侧;
当MOUSE移到屏幕最底部时,该窗体显示在MOUSE的上侧;
平时都在MOUSE的右下侧
谢谢
 
简单!给分吧!
unit Unit1;

interface

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

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
MYHandle:HWND;
procedure WMTimer(var Message: TMessage); message WM_TIMER;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMTimer(var Message: TMessage);
var
p:TPoint;
begin
GetCursorPos(p);
if screen.Width-p.x<=5 then
begin
self.Left:=p.X-self.Width;
self.top:=p.y;
end
else
begin
if Screen.Height-p.y<=5 then
begin
self.Left:=p.X;
self.top:=p.y-self.Height;
end
else
begin
self.Left:=p.X;
self.top:=p.y;
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
MYHandle := AllocateHWnd(WndProc);
KillTimer(MYHandle, 1);
SetTimer(MYHandle, 1, 5, nil);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
KillTimer(MYHandle, 1);
end;

end.
 
接受答案了.
 
后退
顶部