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
VCL-Forms
Language
Delphi 2.x
Views
118
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 //<<< to your 
program as in the following example: 

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