Make your own free website on Tripod.com

Dragging and dropping files on your window from outside (16 jan 1998)

Back Up Next

Author: Eric Aling
Accessed:
Download: Download dropfile.zip ( dropfile.zip ):

Have you wandered how to get filenames through drag and drop[ from the Windows Explorer into your window? I have. Actually, it was quite simple. There are two external functions for this. One to get the name of the drag and dropped file and the other was enabling your window to accept dropped files:

subroutine DragAcceptFiles(ulong hndle, boolean bflag ) library 'shell32.dll'
function ulong DragQueryFileA( ulong ul_Drop, ulong ul_index ref string LPTSTR, ulong cb ) library 'shell32.dll'

The first function enables the window to accept files. You can use any onbject for this, as long as you have a handle. I placed this function in the open and close event of my window. Now, when you drag and drop files, windows sends the WM_DROPFILES event to the received object, if enabled with the DragAcceptFiles() function. This event is mapped to the PowerBuilder pbm_dropfiles event. Map an user event to this called ue_dropfiles so that it gets triggered when files are droppen onto your window/object. Now, to get the filenames of the dropped files, we use the DragQueryFileA() function. This function has as first argument the handle of the structure which containss the filenames. This handle is passed by the WM_DROPFILES event, which you can see as an argument of the ue_dropfiles event. However, this handle is always zero. It should contain the value of Message.WordParm, so we use that one instead:

ue_dropfiles event:
string ls_name
ulong li_i,li_count
// first get the number of files, use as index -1
li_count = DragQueryFileA(Message.WordParm,-1,ls_name,0)
// allocate some space
ls_name = space(255)
// reset listbox
lb_1.Reset()
// get the names and add them to the listbox
for li_i = 1 to li_count
    DragQueryFileA(Message.WordParm,li_i - 1,ls_name,255)
    lb_1.AddItem(ls_Name)
next

That it folks!

Back Up Next