#24 DragStartEx и DragItem

open
nobody
None
5
2014-08-18
2010-01-15
mdw
No

//[function WndProcDragWindow]
function WndProcDragWindow( Sender: PControl; var Msg: TMsg; var Rslt: Integer ): Boolean;
var P: TPoint;
begin
if Msg.message = WM_MOUSEMOVE then
begin
if Sender.FDragging then
begin
{$ifndef wince}
GetCursorPos( P );
{$else wince}
P:= Sender.Client2Screen(MakePoint(SmallInt(LOWORD(Msg.lParam)), SmallInt(HIWORD(Msg.lParam))));
if (Sender.fMouseStartPos.X = -$FFFFFFF) and (Sender.fMouseStartPos.Y = -$FFFFFFF) then begin
Sender.fMouseStartPos:= P;
Exit;
end;
{$endif wince}
P.x := P.x - Sender.fMouseStartPos.x + Sender.fDragStartPos.x;
P.y := P.y - Sender.fMouseStartPos.y + Sender.fDragStartPos.y;
Sender.Position := P;
end;
end;
Result := FALSE;
end;

procedure TControl.DragStartEx;
var StartBounds: TRect;
begin
{$IFNDEF SMALLEST_CODE}
if fDragging then Exit;
{$ENDIF}
{$ifndef wince}
GetCursorPos( fMouseStartPos );
{$else wince}
fMouseStartPos:= MakePoint(-$FFFFFFF, -$FFFFFFF);
{$endif wince}
StartBounds := BoundsRect;
fDragStartPos.x := StartBounds.Left;
fDragStartPos.y := StartBounds.Top;
SetCapture( GetWindowHandle );
fDragging := TRUE;
AttachProc( WndProcDragWindow );
end;

//[function CallDragCallBack]
function CallDragCallBack( Sender: PControl; var Stop: Boolean {$ifdef wince}; P: TPoint {$endif wince}): Boolean;
var {$ifndef wince}P: TPoint;{$endif wince}
Shape, ShapeWas: Integer;
begin
Sender.AttachProc( WndProcSetCursor );
{$ifndef wince}GetCursorPos( P );{$endif wince}
Shape := LoadCursor( 0, PKOLChar(IDC_HAND) );
ShapeWas := Shape;
Result := Sender.fDragCallback( Sender, P.x, P.y, Shape, Stop );
if not Stop then
begin
if not Result then
if Shape = ShapeWas then
Shape := LoadCursor( 0, IDC_NO );
ScreenCursor := Shape;
end
else
begin
ScreenCursor := 0;
Shape := Sender.fCursor;
end;
Windows.SetCursor( Shape );
end;

//[function WndProcDrag]
function WndProcDrag( Sender: PControl; var Msg: TMsg; var Rslt: Integer ): Boolean;
var Stop: Boolean;
begin
if Sender.fDragging then
begin
Stop := FALSE;
case Msg.message of
WM_MOUSEMOVE:
CallDragCallBack( Sender, Stop{$ifdef wince}, Sender.Client2Screen(MakePoint(SmallInt(LOWORD(Msg.lParam)), SmallInt(HIWORD(Msg.lParam)))){$endif wince});
WM_LBUTTONUP, WM_RBUTTONUP:
begin
Stop := TRUE;
CallDragCallBack( Sender, Stop{$ifdef wince}, Sender.Client2Screen(MakePoint(SmallInt(LOWORD(Msg.lParam)), SmallInt(HIWORD(Msg.lParam)))){$endif wince});
end;
else
begin
Result := FALSE;
Exit;
end;
end;
if Stop then
begin
ReleaseCapture;
Sender.fDragging := FALSE;
end
else
begin
Result := TRUE;
exit;
end;
end;
Result := FALSE;
end;

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks