Solved

Need way to accept JPG files when dragging from Google Chrome to Delphi Form

Posted on 2011-02-19
11
525 Views
Last Modified: 2012-05-11
Hi thanks for reading.

I have my delphi app on the left, and Google's Chrome browser on the right.

I simply need a program that, when i drag a JPG file from Google Chrome to my Delphi Form, I just want to save it in the C drive.

I can't seem to find out how to "accept files" from Google Chrome though.

I tried this method but with no luck

http://www.swissdelphicenter.ch/en/showcode.php?id=493

Anyone got any ideas?

Thanks!
0
Comment
Question by:bobbysdog
  • 7
  • 4
11 Comments
 
LVL 14

Expert Comment

by:systan
ID: 34936769
Here you go;  tested code that accepts any image filename from any web browser.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    procedure LBWindowProc(var Message: TMessage);
    procedure AddFile(sFileName: string);

    procedure WMDROPFILES(var Msg: TMessage);
    message WM_DROPFILES;

  public
    { Public declarations }

  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses
  ShellAPI;

var
  OldLBWindowProc: TWndMethod;


procedure TForm1.AddFile(sFileName: string);
begin
  ListBox1.Items.Add(sFilename);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  OldLBWindowProc := ListBox1.WindowProc;
  ListBox1.WindowProc := LBWindowProc;
  DragAcceptFiles(ListBox1.Handle, True);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  ListBox1.WindowProc := OldLBWindowProc;
  DragAcceptFiles(ListBox1.Handle, False);
end;

procedure TForm1.LBWindowProc(var Message: TMessage);
begin
  if Message.Msg = WM_DROPFILES then
    WMDROPFILES(Message);
  OldLBWindowProc(Message);
end;

procedure TForm1.WMDROPFILES(var Msg: TMessage);
var
  c,i, nCount,iSize : integer;
  acFileName : Pchar;
  f:boolean;
begin
nCount := DragQueryFile( msg.WParam,
                           $FFFFFFFF,
                           acFileName,
                           255 );
for i := 0 to nCount-1 do
begin
iSize := DragQueryFile(Msg.wParam, i, nil, 0) + 1;
acFileName := StrAlloc(iSize);
DragQueryFile( msg.WParam, i,acFileName, isize );
AddFile(acFilename);
DragFinish( msg.WParam );
end;
end;

end.

Open in new window

0
 
LVL 14

Expert Comment

by:systan
ID: 34937360
Changes are here; So, you want to save the image to C drive?
procedure TForm1.WMDROPFILES(var Msg: TMessage);
var
  c,i, nCount,iSize : integer;
  acFileName : Pchar;
  f:boolean;
  fn:string;
begin
nCount := DragQueryFile( msg.WParam,
                           $FFFFFFFF,
                           acFileName,
                           255 );

for i := 0 to nCount-1 do
begin
iSize := DragQueryFile(Msg.wParam, i, nil, 0) + 1;
acFileName := StrAlloc(iSize);

DragQueryFile( msg.WParam, i,acFileName, isize );

if FileExists(acFileName) then
begin
fn:=Pchar(ExtractFilename(acFilename));
AddFile(Fn);
CopyFile( acFilename, Pchar('c:\' + fn), false);  //SAVING FILE STARTS HERE
end;


DragFinish( msg.WParam );
end;
end;

Open in new window

0
 

Author Comment

by:bobbysdog
ID: 34937715
Geez thanks Systan!!!

Freakin genius bits of code there.

It works awesome when i use mozilla and Internet Explorer.

The only thing is, it doesnt accept Images from Google Chrome

; (

Tears!

: )

I wonder why chrome is so weird compared to the others...
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 14

Expert Comment

by:systan
ID: 34937959
Ok;
Google Chrome does not keep files in windows temporary system folder,  it keeps files on thy own ways.
You can find it on;
Application Data of the default user logged in.
0
 

Author Comment

by:bobbysdog
ID: 34938113
Thanks so much.

It appears the problem is, i can't even get the program to 'accept' files from google chrome...

i uploaded the above code in a delphi program here

http://www.mediafire.com/?m4njdxy0hoylbck

p.s. i should also note that, when you drag a picture file (in IE or Mozilla) that is wrapped in an A TAG (e.g. when the picture is also a link), then it won't accept files.

Any help anyone can give is so much appreciated!

much thanks!
0
 
LVL 14

Expert Comment

by:systan
ID: 34938329
As I told you,  you can't get accept files from Google chrome because it stores files in different ways.
Instead storing to windows temp files, it stores to Document and Settings\Logged-in User\Application Data\Google\Chrome\

You can't really drag and drop images from Google Chrome to any location,  as I know?,  that is there
design.

If you really want to get the file-name from Google Chrome?, Click Copy Image, then paste it on your Application that do the imaging.   But if you really want to drop it?,  detect the browser if it is Google chrome or not,   then if it is, automate the procedure to paste filename to the BOX.

That's the list that I could help, Open a new question for detect web browser or;
just visit this link;
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26553357.html

You could also ask; automate a copy paste filename to the BOX, if possible.


Good Luck
0
 

Author Comment

by:bobbysdog
ID: 34938435
oh i think i see

>> "You can't really drag and drop images from Google Chrome to any location"

oh so eitherway, its not possible to receive files from Google Chrome?

hmm

what a bummer.

The windows desktop receives jpgs from google chrome. Is there now way to use that method?

but yeah maybe its not possible

photoshop for example receives files from IE and Mozilla but not chrome...


0
 
LVL 14

Accepted Solution

by:
systan earned 500 total points
ID: 34940010
>>>>"You can't really drag and drop images from Google Chrome to any location"
Except that has an imaging purpose.

>>The windows desktop receives jpgs from google chrome
>>>>If you really want to get the file-name from Google Chrome?, Click Copy Image, then paste it on your Application that do the imaging

Ok?

>>Is there now way to use that method?
No, and I've already told you about that, read again my comments.
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26833779.html#34938329
0
 
LVL 14

Expert Comment

by:systan
ID: 34963727
I have resolved the problem, it is possible.
0
 

Author Comment

by:bobbysdog
ID: 35111031
oh wait..

it IS possible now?

what was the solution...?
Thanks!
0
 
LVL 14

Expert Comment

by:systan
ID: 35113558
The answer;
http://melander.dk/


Thanks
Actually I'm not sure, but your the one who want's it, please try it.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 156
Unique identifier on a terminal server (rdp) 4 67
firemonkey keyboard covers the controls 1 37
DBCtrlGrid, Delphi, Scroll 7 26
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question