Based on this drag/drop article: http://delphi.about.com/od/adptips2005/qt/dropontimage.htm
I'm trying to catch an image dragged from Firefox onto a TPanel, I've got something that nearly works, but when I go to copy the file (that I thought would be temporarily created), the file did not exist, what did I miss?
procedure TformMain.FormCreate(Sender: TObject);
begin
originalPanelWindowProc := pnMain.WindowProc;
pnMain.WindowProc := PanelWindowProc;
DragAcceptFiles(pnMain.Handle,true);
end;
procedure TformMain.PanelImageDrop(var Msg: TWMDROPFILES);
var
numFiles : longInt;
buffer : array[0..MAX_PATH] of char;
src,dest : string;
begin
numFiles := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0) ;
if numFiles > 1 then
ShowMessage('You can drop only one image file at a time!')
else begin
DragQueryFile(Msg.Drop, 0, @buffer, sizeof(buffer)) ;
src := string(AnsiString(buffer));
dest := ExtractFilePath(Application.ExeName) + 'graphics\ ' + NewName + ExtractFileExt(src);
ForceDirectories(ExtractFilePath(dest));
CopyFile(PChar(src),PChar(dest),false); (* <-- !!! src does not exist *)
end;
end;
procedure TformMain.PanelWindowProc(var Msg: TMessage);
begin
if Msg.Msg = WM_DROPFILES then
PanelImageDrop(TWMDROPFILES(Msg))
else
originalPanelWindowProc(Msg) ;
end;