DHTMLEdit - Registered Users - Helpdesk
How toPaste Image from Clipboard
Thread Starter: mrcarver Started: 7/19/2008 12:53 AM UTC
Replies: 1
How toPaste Image from Clipboard

How does one paste an image into the Editor that was copied into the clipboard from say FireFox, Paint, Photoshop, etc?

Also, how does drag an image from windows explorer into the Editor?

There appears to be several "How To" on pasting "from" the Editor but not "to" the editor.

Thanks,
Monte Carver
Re: How toPaste Image from Clipboard
Hello Monte:

How does one paste an image into the Editor that was copied into the clipboard from say FireFox, Paint, Photoshop, etc?

procedure TForm1.ToolButton1Click(Sender: TObject);
var
 B: TBitmap;
begin
 if Clipboard.HasFormat(CF_BITMAP) then
 begin
   B := TBitmap.Create;
   try
     B.Assign(Clipboard);
     B.SaveToFile('temp.bmp');
     ProfDHTMLEdit21.InsertImage(ExtractFilePath(Application.ExeName) + 'temp.bmp')
   finally
     B.Free
   end
 end
end;

Also, how does drag an image from windows explorer into the Editor?

------
unit Unit1;

interface

uses
 Forms, Classes, Controls, OleCtrls, ProfDHTMLEdit, Messages, Windows;

type
 TForm1 = class(TForm)
   ProfDHTMLEdit21: TProfDHTMLEdit2;
   procedure FormCreate(Sender: TObject);
 private
   { Private declarations }
   procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

uses ShellAPI;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
 DragAcceptFiles(Handle, True)
end;

procedure TForm1.WMDropFiles(var Msg: TWMDropFiles);
var
 CFileName: array[0..MAX_PATH] of Char;
 P: TPoint;
begin
 try
   if DragQueryFile(Msg.Drop, 0, CFileName, MAX_PATH) > 0 then
     if DragQueryPoint(Msg.Drop, P) then
     begin
       P := ProfDHTMLEdit21.ScreenToClient(ClientToScreen(P));
       if (P.X >= 0) and (P.Y >= 0) then
       begin
         ProfDHTMLEdit21.InsertHTML('<img src="' + CFileName + '">');
         Msg.Result := 0
       end
     end
 finally
   DragFinish(Msg.Drop)
 end
end;

end.
------


-Nicholas