vic4key

Clipboard in Delphi

Sep 2nd, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.32 KB | None | 0 0
  1. program Copier;
  2.  
  3. uses Windows, SysUtils, ShlObj, mrVic;
  4.  
  5. Function CopyFilesFoldersToClipbrd(Paths: String): BOOLEAN; stdcall;
  6. var
  7.     df: TDropFiles;
  8.     i, iLen, iGlobalSize: Integer;
  9.     hGlb: HGLOBAL;
  10.     pData, Ws: PAnsiChar;
  11. begin
  12.     Result:= True;
  13.    
  14.     ZeroMemory(@df,sizeof(df));
  15.     df.pFiles:= sizeof(df);
  16.     df.fWide:= True;
  17.  
  18.     iLen:= Length(Paths);
  19.     iGlobalSize:= sizeof(df) + iLen*2;
  20.    
  21.     hGlb:= GlobalAlloc(GMEM_ZEROINIT or GMEM_MOVEABLE or GMEM_DDESHARE,iGlobalSize);
  22.     pData:= PAnsiChar(GlobalLock(hGlb));
  23.    
  24.     CopyMemory(pData,@df,sizeof(df));
  25.  
  26.     Ws:= pData + sizeof(df);
  27.     i:= 1;
  28.     while (i <= iLen) do
  29.     begin
  30.         Ws[2*i - 2]:= Paths[i];
  31.         Inc(i);
  32.     end;
  33.    
  34.     GlobalUnlock(hGlb);
  35.    
  36.     if (OpenClipboard(0) = False) then
  37.     begin
  38.         VICBox('OpenClipboard::Error');
  39.         Result:= False;
  40.         Exit;
  41.     end;
  42.    
  43.     EmptyClipboard();
  44.    
  45.     if (SetClipboardData(CF_HDROP,hGlb) = 0) then
  46.     begin
  47.         VICBox('SetClipboardData::Error');
  48.         Result:= False;
  49.         Exit;
  50.     end;
  51.  
  52.     if (CloseClipboard = False) then
  53.     begin
  54.         VICBox('CloseClipboard::Error');
  55.         Result:= False;
  56.         Exit;
  57.     end;   
  58. end;
  59.  
  60. begin
  61.     try
  62.         if (CopyFilesFoldersToClipbrd('F:\C\A.txt'#0'F:\D'#0'F:\E') = True) then
  63.             VICBox('The file copied to clipboard success!')
  64.         else
  65.             VICBox('The file copied to clipboard not success!');
  66.     except
  67.         DumpExceptionInfomation;
  68.     end;
  69. end.
Advertisement
Add Comment
Please, Sign In to add comment