unit UnitFileDrag; interface uses classes, TntClasses, ShellAPI; // 得到拖放的文件列表 function GetDragFileNames(hDrop:Cardinal):TTntStrings; implementation // 得到拖放的文件列表 function GetDragFileNames(hDrop:Cardinal):TTntStrings; var cnt, i : integer; pc : array[0..260] of WideChar; begin result := TTntStringList.Create; cnt := DragQueryFileW(hDrop, High(cardinal), nil, 0 ); for i:=0 to cnt-1 do begin DragQueryFileW(hDrop,i,pc,260); result.Add( pc ); end; end; end. |
procedure TForm1.FormCreate(Sender: TObject); begin DragAcceptFiles(Handle, True); end; |
procedure TForm1.MyDrag (var Msg: TWMDropFiles); message WM_DropFiles; var hDrop: Cardinal; ts : TTntStrings; begin hDrop:= Msg.Drop; ts := GetDragFileNames(hDrop); DragFinish (hDrop); Msg.Result:= 0; // ts 中即为拖放的文件 ts.Free; end; |