Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Opening a file by dragging it onto program?

Posted on 2003-02-22
3
Medium Priority
?
149 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:NiZZoBaLL
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 300 total points
ID: 8002448
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
 

Author Comment

by:NiZZoBaLL
ID: 8002679
Thank you very much.  That code was exactly what I needed to help me understand it clearly.
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 8002697
You are welcome :-)
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

580 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