unit Unit1;
interface
uses
Windows, Classes, Controls, Forms,
ActiveX;
type
TForm1 =
class(TForm, IDropTarget)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
public
function DragEnter(
const dataObj: IDataObject; grfKeyState: Longint;
pt: TPoint;
var dwEffect: Longint): HResult;
stdcall;
function DragOver(grfKeyState: Longint; pt: TPoint;
var dwEffect: Longint): HResult;
stdcall;
function DragLeave: HResult;
stdcall;
function Drop(
const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint;
var dwEffect: Longint): HResult;
stdcall;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
Dialogs;
{ TForm1 }
function TForm1.DragEnter(
const dataObj: IDataObject; grfKeyState: Integer;
pt: TPoint;
var dwEffect: Integer): HResult;
begin
dwEffect := DROPEFFECT_COPY;
Result := S_OK;
end;
function TForm1.DragLeave: HResult;
begin
Result := S_OK;
end;
function TForm1.DragOver(grfKeyState: Integer; pt: TPoint;
var dwEffect: Integer): HResult;
begin
Color :=
RGB(Random(256), Random(256), Random(256));
dwEffect := DROPEFFECT_COPY;
Result := S_OK;
end;
function TForm1.Drop(
const dataObj: IDataObject; grfKeyState: Integer;
pt: TPoint;
var dwEffect: Integer): HResult;
begin
dwEffect := DROPEFFECT_COPY;
Result := S_OK;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
R: Integer;
begin
R := RegisterDragDrop(
Handle, Self);
if R <> S_OK
then
ShowMessage('
Couldn''
t initialize Drag''
n''
Drop!');
Randomize;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
RevokeDragDrop(
Handle);
end;
initialization
OleInitialize(
nil);
end.