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 Drag and Drop from FileManager 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
05-Sep-02
Category
Shell API
Language
Delphi 2.x
Views
135
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: William Gerbert 

Drag and Drop from FileManager

Answer:

You need to use these 3 functions from the ShellApi:

DragAcceptFiles - registers whether a window accepts dropped files 
DragQueryFile - retrieves the filename of a dropped file 
DragFinish - releases memory allocated for dropping files


1   uses
2     ShellApi;
3   
4   ..
5   
6   procedure TForm1.FormCreate(Sender: TObject);
7   begin
8     DragAcceptFiles(Form1.Handle, true);
9     Application.OnMessage := AppMessage;
10  end;
11  
12  { message handler procedure }
13  // Delphi 1: type DWord = longint; .. FileIndex := -1;
14  
15  procedure TForm1.AppMessage(var Msg: Tmsg; var Handled: Boolean);
16  const
17    BufferLength: DWORD = 511;
18  var
19    DroppedFilename: string;
20    FileIndex: DWORD;
21    NumDroppedFiles: DWORD;
22    pDroppedFilename: array[0..511] of Char;
23    DroppedFileLength: DWORD;
24  begin
25    if Msg.message = WM_DROPFILES then
26    begin
27      FileIndex := $FFFFFFFF;
28      NumDroppedFiles := DragQueryFile(Msg.WParam, FileIndex,
29        pDroppedFilename, BufferLength);
30  
31      for FileIndex := 0 to (NumDroppedFiles - 1) do
32      begin
33        DroppedFileLength := DragQueryFile(Msg.WParam, FileIndex,
34          pDroppedFilename, BufferLength);
35        DroppedFilename := StrPas(pDroppedFilename);
36  
37        { process the file name you just received }
38      end;
39      DragFinish(Msg.WParam); { important to free memory }
40      Handled := true;
41    end;
42  end;

Notes:

When dropping files, the DroppedFilename is the complete path, not just the 
filename.ext 
It is possible to drag and drop just a directory. So if you are expecting 
filenames, you have to check for existence yourself. 
The filenames come in uppercased.

			
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