Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Drag and Drop with Files


How do I accept files that are dropped on my application?   

    You must interface with the Windows Shell API module to let Windows know that your application accepts dropped files (this can be done in your main form's create event), and then you must respond to the drag events as they happen by creating an event handler. The following is an example of a Delphi form that accepts dropped files and adds the names of the files to a memo component:

    unit Unit ;
    interface
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    type
      TForm  = class(TForm)
        Memo : TMemo;
        procedure FormCreate(Sender: TObject);
      private
        procedure WMDROPFILES(var Message: TWMDROPFILES);
          message WM_DROPFILES;
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form : TForm ;
    implementation
    {$R *.DFM}
    uses ShellApi;
    procedure TForm .FormCreate(Sender: TObject);
    begin
     {Let Windows know we accept dropped files}
      DragAcceptFiles(Form .Handle, True);
    end;
    procedure TForm .WMDROPFILES(var Message: TWMDROPFILES);
    var
      NumFiles : longint;
      i : longint;
      buffer : array[0..255] of char;
    begin
     {How many files are being dropped}
      NumFiles := DragQueryFile(Message.Drop,
                                - ,
                                nil,
                                0);
     {Accept the dropped files}
      for i := 0 to (NumFiles -  ) do begin
        DragQueryFile(Message.Drop,
                      i,
                      @buffer,
                      sizeof(buffer));
        Form .Memo .Lines.Add(buffer);
      end;
    end;
    end.
    

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use