It turns out that this is a bit more complicated then a simple ImageEn demo and requires the use of other third-party components to facilitate the drag and drop. Anders Melander developed a good freeware Drag & Drop Component Suite, (http://melander.dk/delphi/dragdrop/) but he stopped updating it in 2010 so it will not compile with the XE versions of Delphi. So I obtained a copy of the Raize Drop Master 2 components (http://www.raize.com/DevTools/DropMaster/Default.asp).
I then built two applications:
A Target Destination Application that accepts drops from a Target Source Application.
The Target Destination Application contains a TDMGraphicTarget component and a TImageEnView component. The TDMGraphicTarget.AcceptorControl is set to ImageEnView1. Then the following code is added to the DMGraphicTarget1Drop event:
procedure TForm1.DMGraphicTarget1Drop(Sender: TObject; Acceptor: TWinControl;
ThePicture: TPicture; X, Y: Integer);
var
iString: string;
begin
if Assigned(ThePicture) then
begin
{ Assign ThePicture.bitmap to TImageEnView. }
ImageEnView1.Bitmap.Assign(ThePicture.Bitmap);
{ Optionally stretch depending on checkbox state }
if CheckBox1.Checked then
ImageEnView1.Fit
else
ImageEnView1.Zoom := 100;
{ Show in the label what kind of object got dropped }
case (Sender as TDMGraphicTarget).DroppedGraphicFormat of
dgfBitmap: iString := 'Bitmap';
dgfMetafile: iString := 'Metafile';
else
iString := '???'; { Should never happen! }
end;
Label1.caption := 'Dropped a '+ iString;
end;
end;
The Target Source Application contains a TDMGraphicSource and a TImageEnView component. Then in the TImageEnOnbMouseDown event add the following code:
procedure TForm1.ImageEnMView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
iBitmap: TBitmap;
begin
{ Detect a drag with any button }
if DragDetectEx(ImageEnMView1.Handle, POINT(X,Y), Button) then
begin
{ Tell the graphic source which button we got}
DMGraphicSource1.MouseButton := Button;
{ Make a temporary bitmap }
iBitmap := TBitmap.Create;
try
{ Assign the ImageEnMView1.Bitmap to the temporary bitmap }
iBitmap.Assign(ImageEnMView1.Bitmap);
{ Now, we have a bitmap, so assign it to the graphic source's picture }
DMGraphicSource1.Picture.Graphic := iBitmap;
{ Now do the drag! }
DMGraphicSource1.Execute;
{ In case we made a big bitmap, let it go. Otherwise, it will live on unnecessarily in the Picture property of the TDMGraphicSource. }
DMGraphicSource1.Picture := nil;
finally
{ Clean up. }
iBitmap.Free;
end;
end;
end;
The Target Source Application can also drag images to other applications like Microsoft Word. Phew... it works nicely...
Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development