Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Let them drag and drop files on your program Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
16-Jan-03
Category
Files Operation
Language
Delphi 2.x
Views
164
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

Let them drag and drop files on your program

Answer:

If you want to let your users drag and drop files on your program from the File 
Manager and Windows Explorer, simply add the code inside //>>> and 
1   //<<< to your program as in the following example: 
2   
3   unit dropfile;
4   
5   interface
6   
7   uses
8     Windows, Messages, SysUtils, Classes,
9     Graphics, Controls, Forms, Dialogs;
10  
11  type
12    TForm1 = class(TForm)
13      procedure FormCreate(Sender: TObject);
14    private
15      { Private declarations }
16    public
17      { Public declarations }
18  
19      //>>>
20  
21      // declare our DROPFILES message handler
22      procedure AcceptFiles(var msg: TMessage);
23        message WM_DROPFILES;
24      //<<<
25    end;
26  
27  var
28    Form1: TForm1;
29  
30  implementation
31  
32  uses
33    //>>>
34    //
35    // this unit contains certain
36    // functions that we'll be using
37    //
38    ShellAPI;
39  //<<<
40  
41  {$R *.DFM}
42  
43  //>>>
44  
45  procedure TForm1.AcceptFiles(var msg: TMessage);
46  const
47    cnMaxFileNameLen = 255;
48  var
49    i,
50      nCount: integer;
51    acFileName: array[0..cnMaxFileNameLen] of char;
52  begin
53    // find out how many files we're accepting
54    nCount := DragQueryFile(msg.WParam,
55      $FFFFFFFF,
56      acFileName,
57      cnMaxFileNameLen);
58  
59    // query Windows one at a time for the file name
60    for i := 0 to nCount - 1 do
61    begin
62      DragQueryFile(msg.WParam, i,
63        acFileName, cnMaxFileNameLen);
64  
65      // do your thing with the acFileName
66      MessageBox(Handle, acFileName, '', MB_OK);
67    end;
68  
69    // let Windows know that you're done
70    DragFinish(msg.WParam);
71  end;
72  //<<<
73  
74  procedure TForm1.FormCreate(Sender: TObject);
75  begin
76    //>>>
77    //
78    // tell Windows that you're
79    // accepting drag and drop files
80    //
81    DragAcceptFiles(Handle, True);
82    //<<<
83  end;
84  
85  end.


Now you can drag and drop files on the form that you registered as a recipient of dropped files by calling the "DragAcceptFiles()" function as in the above example.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC