Hi
I found the following code on the web, and was wondering if you could
not modify it. Anyway I hope it works, and what you are looking for?
By the looks of it, the code came from a Delphi 2 web site, so there may
be a couple of conversion errors.
<snip>
unit Unit1;
interface
{
by Wang Zhen- [EMAIL PROTECTED]
}
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
procedure Magnetize(var nl,nt:integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
LastX, LastY: Integer; //keep the coordinates of cursor
WinampRect:TRect; //stores the region of target window
hwnd_Winamp:HWND; //the handle of Winamp's main window
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
nLeft,nTop:integer;
begin
//check whether the form is being dragged
if HiWord(GetAsyncKeyState(VK_LBUTTON)) > 0 then
begin
//calculate new position
nleft := Left + X - LastX;
nTop := Top + Y - LastY;
//adjust the position if Winamp is found
if hwnd_Winamp>0 then
Magnetize(nleft,ntop);
SetBounds(nLeft,nTop,width,height);
end;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const
ClassName='Winamp v1.x'; //the classname of Winamp's main window
{ Replace the line with "ClassName='TAppBuilder'" if your Delphi
itself hungers for some magnetic power. }
begin
//save the coordinates
LastX := X;
LastY := Y;
//try to locate Winamp
hwnd_Winamp := FindWindow(ClassName,nil);
if hwnd_Winamp>0 then
GetWindowRect(hwnd_Winamp, WinampRect);
end;
procedure TForm1.Magnetize(var nl,nt:integer);
//two simple embedded functions
function Min(a,b:integer):integer;
begin
if a>b then result:=b else result:=a;
end;
function Max(a,b:integer):integer;
begin
if a < b then result:=b else result:=a;
end;
var
H_Overlapped,V_Overlapped:boolean;
tw,ww,wh:integer;
const
MagneticForce:integer=50;
{ in other words, when two windows are nearer than 50 pixels, they
will be aligned automatically. Remember, 50 is used for demonstration
purposes only.
It's quite exaggerative if you want to simulate the effect of
Winamp. }
begin
ww := WinampRect.Right-WinampRect.Left;
tw := Max(WinampRect.Right,nl+Width)-Min(WinampRect.Left,nl);
H_Overlapped := tw<=(Width+ww);
wh := WinampRect.Bottom-WinampRect.Top;
tw := Max(WinampRect.Bottom,nt+Height)-Min(WinampRect.Top,nt);
V_Overlapped := tw<=(Height+wh);
//change the position when the two windows are close enough
if H_Overlapped then
begin
if Abs(WinampRect.Bottom-nt)< MagneticForce then nt :=
WinampRect.Bottom
else if Abs(nt+Height-WinampRect.Top)< MagneticForce then nt
:= WinampRect.Top-Height;
end;
if V_Overlapped then
begin
if Abs(WinampRect.Right-nl)< MagneticForce then nl :=
WinampRect.Right
else if Abs(nl+Width-WinampRect.Left)< MagneticForce then nl
:= WinampRect.Left-Width;
end;
end;
end.
</snip>
Thanks
Johan Fourie
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Ross Levis
Sent: 07 May 2005 12:11
To: Borland's Delphi Discussion List
Subject: Re: Snaping (docking) Windows
Unfortunately I can't get JCL to install on my D7 Personal. It's
looking for files that don't exist such as Provider.pas. And then it
appears to have problems with CLX packages. I haven't installed CLX
only VCL.
I've asked for help on the JVCL mailing list, so hopefully I receive a
reply and it can be installed on this version of Delphi. If anyone has
any ideas then that would be much appreciated.
Regards,
Ross.
----- Original Message -----
From: "Marcin Bury" <[EMAIL PROTECTED]>
To: "Borland's Delphi Discussion List" <[email protected]>
Sent: Thursday, May 05, 2005 10:53 PM
Subject: Re: Snaping (docking) Windows
Ross,
Jedi VCL library has a component named JvFormMagnet. I didn't use it but
it
might be worth checking.
Marcin
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi
NOTICE: Please note that this eMail, and the contents thereof, is subject to
the standard arivia.kom email disclaimer which may be found at:
http://www.arivia.co.za/internet/disclaimer.htm. If you cannot access the
disclaimer through the URL attached, and you wish to receive a copy thereof,
please send an eMail to [EMAIL PROTECTED] or call (011) 233-0800. You will
receive the disclaimer by return email or fax.
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi