Drag & Drop from Windows Explorer to PowerBuilder application


It isn’t a big thing but user-friendly to let your user drop some files in your PowerBuilder application. Maybe to import, merge, strip, archive, …. you name it Zwinkerndes Smiley

1. Insert the external functions to your window object.

function ulong DragQueryFileW( ulong hDrop, ulong iFile, ref string LPTSTR, ulong cb ) library 'shell32.dll'
subroutine DragAcceptFiles(ulong h, boolean b ) library 'shell32.dll' 

2. Insert a custom event with ID “pbm_dropfiles” to you window object and insert some code like this.

string     ls_filename
ulong     ll_fileCount
ulong     ll_index
long        ll_row

ll_fileCount = DragQueryFileW(Message.WordParm,-1,ls_filename,0)
ls_filename = space(255)
for ll_index = 1 to ll_fileCount
    DragQueryFileW(Message.WordParm,ll_index - 1,ls_filename,255)
    ll_row = dw_files.insertRow ( 0 )
    dw_files.setItem ( ll_row, "filename", ls_filename);


3. Make sure you enabled and disabled Drop behavior in open and close event of the window object.

DragAcceptFiles(handle(this),true) //open
DragAcceptFiles(handle(this),false) //close

That’s it!

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>