Mega Code Archive

 
Categories / Delphi / Examples
 

How to enable drag and drop in your application

Title: How to enable drag and drop in your application procedure AcceptFiles( var msg : TMessage );message WM_DROPFILES; After that, add ??shellapi?? unit to the implementation use. implementation uses shellapi; And then the code for processing the drop files procedure TForm1.AcceptFiles( var msg : TMessage ); const cnMaxFileNameLen = 255; var i, nCount : integer; acFileName : array [0..cnMaxFileNameLen] of char; begin nCount := DragQueryFile( msg.WParam,$FFFFFFFF,acFileName,cnMaxFileNameLen ); for i := 0 to nCount-1 do begin DragQueryFile( msg.WParam, i, acFileName, cnMaxFileNameLen ); MessageBox( Handle, acFileName, '', MB_OK ); end; DragFinish( msg.WParam ); end; To enable Drag and drop you have to add the following function to the formcreate DragAcceptFiles( Handle, True );