Advertisement
Guest User

Untitled

a guest
Jun 4th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.65 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, FileCtrl, ActiveX, ShlObj, ComObj, Vcl.Buttons;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     SpeedButton2: TSpeedButton;
  12.     procedure SpeedButton2Click(Sender: TObject);
  13.   private
  14.     { Private declarations }
  15.   public
  16.  
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.dfm}
  25.  
  26. function GetFileListDataObject(const Directory: string; Files:
  27.   TStrings):
  28.   IDataObject;
  29. type
  30.   PArrayOfPItemIDList = ^TArrayOfPItemIDList;
  31.   TArrayOfPItemIDList = array[0..0] of PItemIDList;
  32. var
  33.   Malloc: IMalloc;
  34.   Root: IShellFolder;
  35.   FolderPidl: PItemIDList;
  36.   Folder: IShellFolder;
  37.   p: PArrayOfPItemIDList;
  38.   chEaten: ULONG;
  39.   dwAttributes: ULONG;
  40.   FileCount: Integer;
  41.   i: Integer;
  42. begin
  43.   Result := nil;
  44.   if Files.Count = 0 then
  45.     Exit;
  46.   OleCheck(SHGetMalloc(Malloc));
  47.   OleCheck(SHGetDesktopFolder(Root));
  48.   OleCheck(Root.ParseDisplayName(0, nil,
  49.     PWideChar(WideString(Directory)),
  50.     chEaten, FolderPidl, dwAttributes));
  51.   try
  52.     OleCheck(Root.BindToObject(FolderPidl, nil, IShellFolder,
  53.     Pointer(Folder)));
  54.     FileCount := Files.Count;
  55.     p := AllocMem(SizeOf(PItemIDList) * FileCount);
  56.     try
  57.       for i := 0 to FileCount - 1 do
  58.       begin
  59.         OleCheck(Folder.ParseDisplayName(0, nil,
  60.                  PWideChar(WideString(Files[i])), chEaten, p^[i],
  61.                  dwAttributes));
  62.       end;
  63.       OleCheck(Folder.GetUIObjectOf(0, FileCount, p^[0], IDataObject,
  64.         nil,
  65.         Pointer(Result)));
  66.     finally
  67.       for i := 0 to FileCount - 1 do
  68.       begin
  69.         if p^[i] <> nil then
  70.           Malloc.Free(p^[i]);
  71.       end;
  72.       FreeMem(p);
  73.     end;
  74.   finally
  75.     Malloc.Free(FolderPidl);
  76.   end;
  77. end;
  78.  
  79.  
  80.  
  81. procedure TForm1.SpeedButton2Click(Sender: TObject);
  82. var
  83.   SelFileList: TStrings;
  84.   I: Integer;
  85.   DataObject: IDataObject;
  86.   Effect: Integer;
  87.   CLSID_SendMail: TGUID;
  88.   DT: IDropTarget;
  89.   P: TPoint;
  90.  
  91. begin
  92.   CLSID_SendMail := StringToGUID('{9E56BE60-C50F-11CF-9A2C-00A0C90A90CE}');
  93.   with TOpenDialog.Create(self) do
  94.   try
  95.     SelFileList := TStringlist.Create;
  96.     if Execute then
  97.     begin
  98.       SelFileList.Add(FileName);
  99.       SelFileList.Add(FileName);
  100.       SelFileList.Add(FileName);
  101.       DataObject := GetFileListDataObject(ExtractFilePath(FileName), SelFileList);
  102.       Effect := DROPEFFECT_NONE;
  103.       CoCreateInstance(CLSID_SendMail, nil, CLSCTX_ALL, IDropTarget, DT);
  104.       DT.DragEnter(DataObject, MK_LBUTTON, P, Effect);
  105.       DT.Drop(DataObject, MK_LBUTTON, P, Effect);
  106.     end;
  107.   finally
  108.     free;
  109.     SelFileList.Free;
  110.   end;
  111. end;
  112.  
  113. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement