WinAmp style (continuous) window dragging
Quote
dr...@thjzgn.com wrote:
> I noticed that when you drag the WinAmp (an MP3 player) main window it
> remains solid. (as opposed to the usual outline dragging). Can this be done
> in Delphi 3?
Firstly, the WinAmp window is a borderless one, with completely
user-defined contents. Since it lacks a standard title-bar, such a
window would normally be unable to be dragged in the conventional
outline manner without resorting to manually intercepting hit-test
Windows messages etc.
To add WinAmp's solid dragging behaviour to a form, use the following
variable declaration and methods. Note that with this code, any part of
the form not otherwise populated with buttons etc can be used to drag
the form. If you wanted to have a special form area for dragging - i.e.
the equivalent of a title-bar - you would just make the FormMouseDown
method a little more complex by adding a check whether X and Y were
within certain bounds.
var IsDragging : boolean;
OriginalX, OriginalY : integer;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var DeltaX,DeltaY : integer;
begin
if IsDragging then
begin
DeltaX:=X-OriginalX;
DeltaY:=Y-OriginalY;
Left:=Left+DeltaX;
Top:=Top+DeltaY
end;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
IsDragging:=true;
OriginalX:=X;
OriginalY:=Y;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
IsDragging:=False;
end;
Works in D1 and I am sure later versions too.
--
David Gosnell
These personal views are not necessarily those of my employer.
(please remove "uce-buster." from my e-mail address if replying direct)