PDA

View Full Version : Drag and Drop not working with Firefox



czar
21-08-2009, 09:54 PM
Hi all,

For an application I am making I want to allow the user to drag an image off their browser directly into my app. There are a number of examples on the net and that is what I used. The code i have works with IE and also seems to work in Windows XP.

However, with Vista dragging a jpg off a internet site to the app results in the temp file not being available.

When dragging from firefox acFileName has a link to a file that no longer exists. I can't work out why that happens. If I drag from firefox to say Photoshop then I have no problems.

Anyone got a solution? Or a different routine I could try?


procedure TForm1.AcceptFiles(var Msg: TMessage);
const
cnMaxFileNameLen = 255;
var
nCount, i : Integer;
acFileName : Array [0..cnMaxFileNameLen] Of Char;
DropPosition : TPoint;
DropControl : TControl;
begin
nCount := DragQueryFile(Msg.WParam,$FFFFFFFF,acFileName,cnMa xFileNameLen);


for i := 0 to -1 + nCount do
begin
Try
DragQueryFile(Msg.WParam,i,acFileName,cnMaxFileNam eLen);


If UpperCase(ExtractFileExt(acFileName)) = '.JPG' Then
begin
image2.Picture.LoadFromFile(acFileName);
end
Else If UpperCase(ExtractFileExt(acFileName)) = '.BMP' Then
begin
image2.Picture.LoadFromFile(acFileName);
end;
Finally
memo1.Lines.Insert(0, acFileName) ;
end;
end;
DragFinish(Msg.WParam);
end;

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

http://www.orangepeel.co.nz/cabal/dragndrop_delphi.zip

So it does work with images off local machine and using IE but it doesn't work correctly for Firefox (might be working under windows xp)