就是如同在操作系统中点中文件后右键弹出菜单,可以“复制”、“剪切”文件到剪贴板?
网上看到的都是直接把一个文件复制到另一个目录下,我只想实现让用户“复制”、“剪切”,至于他最后到操作系统下是不是“粘贴”,不在程序里实现的那种效果?

解决方案 »

  1.   

    http://www.mscto.com/Delphi/27969205.html
    参考
      

  2.   

    BOOL   CopyFile(         LPCTSTR   lpExistingFileName, //   pointer   to   name   of   an   existing   file   
            LPCTSTR   lpNewFileName, //   pointer   to   filename   to   copy   to   
            BOOL   bFailIfExists   //   flag   for   operation   if   file   exists   
          ); 
      HANDLE   CreateFile(         LPCTSTR   lpFileName, //   pointer   to   name   of   the   file   
            DWORD   dwDesiredAccess, //   access   (read-write)   mode   
            DWORD   dwShareMode, //   share   mode   
            LPSECURITY_ATTRIBUTES   lpSecurityAttributes, //   pointer   to   security   attributes   
            DWORD   dwCreationDistribution, //   how   to   create   
            DWORD   dwFlagsAndAttributes, //   file   attributes   
            HANDLE   hTemplateFile   //   handle   to   file   with   attributes   to   copy     
          ); 
      

  3.   

    1.SendMessage:procedure TForm1.Cut1Click(Sender: TObject);
    begin
    SendMessage (ActiveControl.Handle, WM_Cut, 0, 0);
    end;
    procedure TForm1.Copy1Click(Sender: TObject);
    begin
    SendMessage (ActiveControl.Handle, WM_Copy, 0, 0);
    end;procedure TForm1.Paste1Click(Sender: TObject);
    begin
    SendMessage (ActiveControl.Handle, WM_Paste, 0, 0);
    end;如果你开发一个MDI应用程序,你需要保证信息发送到活动子窗口,使用: ActiveMDIChild.ActiveControl.Handle
      

  4.   

    2.看下面:int GetClipboardFormatName(
      UINT format,            // clipboard format to retrieve
      LPTSTR lpszFormatName,  // address of buffer for name
      int cchMaxCount         // length of name string in characters
    );
    如果format=CF_HDROP就是文件了HANDLE SetClipboardData(
      UINT uFormat, // clipboard format
      HANDLE hMem   // data handle
    );Delphi定义了两个格式:CF_PICTURE和CF_COMPONENT.
    用户可以定义自己的格式.不过因为Formats是WORD格式,所以系统中只能有
    16种格式.打开ClipBrd单元,可以查到.
      CF_PICTURE := RegisterClipboardFormat('Delphi Picture');
      CF_COMPONENT := RegisterClipboardFormat('Delphi Component');
    你添加:
      CF_MYFILE := RegisterClipboardFormat(' My File Format');剪贴板操作:
    打开;
    清空;
    SetFormatData(CF_TEXT)  --->文件名;
    SetFormatData(CF_MYFILE)  --->文件内容
    关闭;如果你只对文件名感兴趣,那只是一个文本格式.取出内容,用FileExists查询
    是否存在即可.
    registerClipboardFormat函数登记新的剪贴板格式
    格式的值在OXC000和0XFFF范围
    IsClipboardFormatAvailable函数判断剪贴板是否包含指定格式数据
    格式可用返回非零值
    windows是有定义:
    可以用cf_Hdrop;uses shlobj,activex,clipbrd;procedure TForm1.Button1Click(Sender: TObject);
    var
      FE:TFormatEtc;
      Medium: TStgMedium;
      FileName:String;
      dropfiles:PDropFiles;
      pFile:PChar;
    begin
      FileName:='c:\1.bmp';
      FE.cfFormat := CF_HDROP;
      FE.dwAspect := DVASPECT_CONTENT;
      FE.tymed := TYMED_HGLOBAL;
      Medium.hGlobal := GlobalAlloc(GMEM_SHARE or GMEM_ZEROINIT, SizeOf(TDropFiles)+length(FileName)+1);
      if Medium.hGlobal<>0 then begin
        Medium.tymed := TYMED_HGLOBAL;
        dropfiles := GlobalLock(Medium.hGlobal);
        try
          dropfiles^.pfiles := SizeOf(TDropFiles);
          dropfiles^.fwide := False;
          longint(pFile) := longint(dropfiles)+SizeOf(TDropFiles);
          StrPCopy(pFile,FileName);
          Inc(pFile, Length(FileName)+1);
          pFile^ := #0;
        finally
          GlobalUnlock(Medium.hGlobal);
        end;
        Clipboard.SetAsHandle(CF_HDROP,Medium.hGlobal);
      end;
    end;
    上面这个例子把filename这个文件放在了clipboard上