需要:程序中将文件复制或剪切到剪切板.用Windows自己的粘贴能粘贴出来.
我的意思是:类似memo1.CutToClipBoard,只是我要操作的是文件或文件夹

解决方案 »

  1.   

    你可以声明一个剪贴板类:ClipBoard:TclipBoard; //剪贴板
    把文件复制到剪贴板中:ClipBoard.Assign(scrImage.Picture);
    这是文件的粘贴(这里假设是位图):
     if Clipboard.HasFormat(CF_BITMAP) then
        begin
          Bitmap := TBitmap.Create;
          try
            Bitmap.Assign(Clipboard);
            scrImage.Canvas.Draw(0, 0, Bitmap);
          finally
            Bitmap.Free;
          end;
        end;
    具体的要粘贴什么得看你的复制的是什么,主要靠Clipboard.HasFormat(CF_BITMAP)来判断
      

  2.   

    是任意文件
    用Windows自己的粘贴能粘贴出来(就是Windows自己的复制和剪切文件功能).
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      hMem : THandle;
      Pmem:Pchar;
      ss:Pchar;
    begin
      ss:='你好吗?';
      hMem := GlobalAlloc(GHND or GMEM_DDESHARE, 20);
      if hMem <> 0 then
      begin
        pMem := GlobalLock(hMem); {加锁全局内存块}
        if pMem <> nil then
        begin
          StrCopy(pMem,ss); {向全局内存块写入数据}
          GlobalUnlock(hMem); {解锁全局内存块}
        end;
      end;
      OpenClipboard(0);
      EmptyClipboard();
      SetClipboardData(CF_TEXT, hMem);
      CloseClipboard();
      SendMessage(memo1.Handle, WM_PASTE, 0, 0);
      GlobalFree(hMem);
    end;
    这是一个把字串'你好吗?' 粘贴到剪切板的全过程.
    文件和text文本的区别就在SetClipboardData(CF_TEXT, hMem);这一步.(我是这么认为的)
    你可以设置SetClipboardData()的第一个参数来说明你要复制的是什么类型的文件.
    给你帖出几个:
    HANDLE SetClipboardData(    UINT uFormat, // clipboard format  
        HANDLE hMem  // data handle 
       );The uFormat parameter can identify a registered clipboard format, or it can be one of the following values: Value Meaning
    CF_BITMAP A handle to a bitmap (HBITMAP).
    CF_DIB A memory object containing a BITMAPINFO structure followed by the bitmap bits.
    CF_DIF Software Arts' Data Interchange Format.
    CF_DSPBITMAP Bitmap display format associated with a private format. The hMem parameter must be a handle of data that can be displayed in bitmap format in lieu of the privately formatted data.
    CF_DSPENHMETAFILE Enhanced metafile display format associated with a private format. The hMem parameter must be a handle of data that can be displayed in enhanced metafile format in lieu of the privately formatted data.
    CF_DSPMETAFILEPICT Metafile-picture display format associated with a private format. The hMem parameter must be a handle of data that can be displayed in metafile-picture format in lieu of the privately formatted data.
    CF_DSPTEXT Text display format associated with a private format. The hMem parameter must be a handle of data that can be displayed in text format in lieu of the privately formatted data.
    CF_ENHMETAFILE A handle of an enhanced metafile (HENHMETAFILE).
    CF_GDIOBJFIRST through CF_GDIOBJLAST Range of integer values for application-defined GDI object clipboard formats. Handles associated with clipboard formats in this range are not automatically deleted using the GlobalFree function when the clipboard is emptied. Also, when using values in this range, the hMem parameter is not a handle to a GDI object, but is a handle allocated by the GlobalAlloc function with the GMEM_DDESHARE and GMEM_MOVEABLE flags.
    CF_HDROP A handle of type HDROP that identifies a list of files. An application can retrieve information about the files by passing the handle to the DragQueryFile functions. 
    CF_LOCALE The data is a handle to the locale identifier associated with text in the clipboard. When you close the clipboard, if it contains CF_TEXT data but no CF_LOCALE data, the system automatically sets the CF_LOCALE format to the current input locale. You can use the CF_LOCALE format to associate a different locale with the clipboard text.An application that pastes text from the clipboard can retrieve this format to determine which character set was used to generate the text.Note that the clipboard does not support plain text in multiple character sets. To achieve this, use a fomatted text data type such as RTF instead.Windows NT: The system uses the code page associated with CF_LOCALE to implicitly convert from CF_TEXT to CF_UNICODETEXT. Therefore, the correct code page table is used for the conversion.
    CF_METAFILEPICT Handle of a metafile picture format as defined by the METAFILEPICT structure. When passing a CF_METAFILEPICT handle by means of dynamic data exchange (DDE), the application responsible for deleting hMem should also free the metafile referred to by the CF_METAFILEPICT handle.
    CF_OEMTEXT Text format containing characters in the OEM character set. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data.
    CF_OWNERDISPLAY Owner-display format. The clipboard owner must display and update the clipboard viewer window, and receive the WM_ASKCBFORMATNAME, WM_HSCROLLCLIPBOARD, WM_PAINTCLIPBOARD, WM_SIZECLIPBOARD, and WM_VSCROLLCLIPBOARD messages. The hMem parameter must be NULL.
    CF_PALETTE Handle of a color palette. Whenever an application places data in the clipboard that depends on or assumes a color palette, it should place the palette on the clipboard as well.
    If the clipboard contains data in the CF_PALETTE (logical color palette) format, the application should use the SelectPalette and RealizePalette functions to realize (compare) any other data in the clipboard against that logical palette.
    When displaying clipboard data, Windows clipboard always uses as its current palette any object on the clipboard that is in the CF_PALETTE format.
    CF_PENDATA Data for the pen extensions to the Microsoft Windows for Pen Computing.
    CF_PRIVATEFIRST through CF_PRIVATELAST Range of integer values for private clipboard formats. Handles associated with private clipboard formats are not freed automatically; the clipboard owner must free such handles, typically in response to the WM_DESTROYCLIPBOARD message.
    CF_RIFF Represents audio data more complex than can be represented in a CF_WAVE standard wave format.
    CF_SYLK Microsoft Symbolic Link (SYLK) format.
    CF_TEXT Text format. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data. Use this format for ANSI text.
    CF_WAVE Represents audio data in one of the standard wave formats, such as 11 kHz or 22 kHz pulse code modulation (PCM).
    CF_TIFF Tagged-image file format.
    CF_UNICODETEXT Windows NT only: Unicode text format. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data.你看你要操作的是哪一类的文件.就指定哪一个参数..
    (具体我没有做过,只给出个思想.哈哈)