Example of Multi-file drag-and-drop obtaining path in Delphi

Source: Internet
Author: User

UnitUnit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, shellapi;

Type
Tform1 =Class(Tform)
Memo1: tmemo;
ProcedureFormcreate (Sender: tobject );
Private
// When the file is dragged to the form, the system will send the wm_drapfiles event to the form,
// Therefore, we can obtain the total number of files and file names during wmdropfiles.
ProcedureWmdropfiles (VaRMSG: tmessage); message wm_dropfiles;
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

ProcedureTform1.formcreate (Sender: tobject );
Begin
// Enable the file drag-and-drop function when the program starts. When the second parameter is true,
// Enable file drag and drop. If it is false, file drag and drop are prohibited.
Dragacceptfiles (handle, true );
End;

ProcedureTform1.wmdropfiles (VaRMSG: tmessage );
VaR
Filescount: integer; // total number of files
I: integer;
Filename:Array[0 .. 255]OfChar;
Begin
Try
Memo1.clear;
// Obtain the total number of objects
Filescount: = dragqueryfile (msg. wparam, $ ffffffff,Nil, 0 );
Memo1.lines. Add ('Total number of files: '+ inttostr (filescount ));
// Get the file name
ForI: = 0ToFilescount-1Do
Begin
Dragqueryfile (msg. wparam, I, filename, 256 );
Memo1.lines. Add (filename)
End;
Finally

Dragfinish (msg. wparam );
End;
End;

End.


From Weizhi note (wiz)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.