Opening a file by dragging it onto program?

I am writing a program and I am having trouble putting together the necessary code to be able to drag a file onto the program and having it open up and already be displayed like you can do with a JPEG in photoshop.  

If I drag a file onto the program right now it will open the program but it will not actually open the file.  The way the program is designed is there is a blank form with a tree view ontop of it that I use to open specific files and they get displayed on the open form.  What I need to know is how to tell the program what to do with the file I drop onto it or basically how to get the program to open the file automatically after dropping it onto the program.  Thank you for your time.
NiZZoBaLLAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed NasmanSoftware DeveloperCommented:
Hello

  Handle the WM_DropFiles message, here's a quick example

TForm1 = class(TForm)
  ....
  public
    procedure WMDropFiles(var Msg: TWmDropFiles); message WM_DropFiles;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses
  ShellAPI, Jpeg;

procedure TForm1.WMDropFiles(var Msg: TWmDropFiles);
var
  Img: string;
begin
  SetLength(Img,128);
  DragQueryFile(Msg.Drop,0,PChar(Img),128);
  Img := PChar(Img);
  if UpperCase(ExtractFileExt(Img)) = '.JPG' then
    Image1.Picture.LoadFromFile(Img);
end;

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

end.  

Best regards
Mohammed Nasman
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NiZZoBaLLAuthor Commented:
Thank you very much.  That code was exactly what I needed to help me understand it clearly.
0
Mohammed NasmanSoftware DeveloperCommented:
You are welcome :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.