?
Solved

Opening a file by dragging it onto program?

Posted on 2003-02-22
3
Medium Priority
?
145 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

777 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