juhara.com

  • Narrow screen resolution
  • Wide screen resolution
  • Decrease font size
  • Default font size
  • Increase font size
Home Articles Delphi Programming Drag Drop Operation from Windows Explorer onto a Control
Drag Drop Operation from Windows Explorer onto a Control PDF Print E-mail
Written by Zamrony P. Juhara   
Wednesday, 29 April 2009 12:10
Article Index
Drag Drop Operation from Windows Explorer onto a Control
Implementation
Example utilization
All Pages

Actually, this article was my post at Delphindo mailing list to answer question how to get list of filenames dragged and dropped from Windows Explorer onto a control.

If you ever use WinAmp, you know that we can add audio file into playlist by dragging and dropping files from Windows Explorer into WinAmp playlist listbox. The question is how?

Registering Window Handle

To get notified when drag-drop happen, we must register our window handle by calling DragAcceptFiles() function declared in ShellAPI.pas unit.

DragAcceptFiles(aWinHandle,FAccept);

This function expects two parameters. First parameter is handle that will receive drag-drop operation, second parameter tells whether it is registration or unregistration process. If it is true, window handle will receive notification when drag drop operation occured and if it is false, window handle will be removed from drag- drop notification list.

Handling WM_DROPFILES Message

WM_DROPFILES message will be sent to window handle registered for notification. wParam will hold handle to drag drop operation occured. We use this handle to get more information such retrieve number of files drag-dropped and also their names.

Because we use window handle, only control that have window handle is able to receive this message. WM_DROPFILES will be sent via window procedure of the corresponding window handle.

Get Number of Files Dragged Dropped

DragQueryFile() is used to get number of file drag-dropped.

total_file:=DragQueryFile(hDrop,$FFFFFFFF,nil,0);

This function needs four parameters, but to get number of file, only two parameters that is relevant. The rest is set to nil and 0. First parameter is drag drop handle, and second is file index, whioch must be set to $FFFFFFFF.

Get Length of Filename Dragged Dropped

We need to know length of filename, to be able to allocate buffer to hold filename data. To get length of filename we use same function, DragQueyFile(), but with a little bit different parameters, i.e, we set Fileindex to 0 - (total_file-1).

filename_len:=DragQueryFile(hDrop,FileIndex,nil,0);

Get Filename Dragged Dropped

To get file name, we use DragQueyFile(), Fileindex is set to 0 - (total_file-1),

DragQueryFile(hDrop,FileIndex,aFilename,filename_len);

afilename is data of type of PChar previously allocated with buffer length of filename_len.

Finishing Drag Drop Operation

We callDragFinish() to tell Windows that we are done with drag drop operation. This function will free memories allocated for filename buffer. We pass drag drop handle to this function.



Last Updated on Friday, 06 November 2009 14:49
 

Language

IndonesianEnglish (United Kingdom)

Game Institute
DAZ3D

Is this article helpful? Help this site improve by donating. Any amount is appreciated.