与在文件夹上面点击右键 选择剪切一样

解决方案 »

  1.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}uses ShellAPI, FileCtrl;Function MoveFileAndDir(SourceDir,DestDir:String):Boolean;
    Var
      Opstruc: TSHFileOpStruct;
      frombuf,tobuf: Array[0..128] of Char;
    begin
      FillChar(frombuf,Sizeof(frombuf),0);
      FillChar(tobuf,Sizeof(tobuf),0);
      StrPcopy(frombuf,SourceDir);
      StrPcopy(tobuf,DestDir);
      With Opstruc Do
      Begin
        Wnd:=0;
        wFunc:=FO_COPY;
        pFrom:=@frombuf;
        pTo:=@tobuf;
        fFlags:=FOF_NOCONFIRMATION;
        fAnyOperationsAborted:=False;
        hNameMappings:=Nil;
        lpszProgressTitle:=Nil;
      end;
      try
        ShFileOperation(OpStruc);
        Opstruc.wFunc:= FO_DELETE;
        ShFileOperation(OpStruc);    
        Result:=True;
      except
        Result:=False;
      end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      MoveFileAndDir('JT','D:\JT1')   // JT 原文件夹, D:\JT1 目标文件夹
    end;end.
      

  2.   

    uses shlobj,activex,clipbrd; 
    procedure TForm1.Button1Click(Sender: TObject);
    var 
      FE:TFormatEtc;
      Medium: TStgMedium;
      FileName:String;
      dropfiles:PDropFiles;
      pFile:PChar;
    begin 
      FileName:='c:\abc;//这里是关键。
      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;
    于是,楼主的问题解决。
      

  3.   

    少打了个引号,不好意思,重贴代码,也希望楼主早点给分。
    uses shlobj,activex,clipbrd;  
    procedure TForm1.Button1Click(Sender: TObject);
    var  
      FE:TFormatEtc;
      Medium: TStgMedium;
      FileName:String;
      dropfiles:PDropFiles;
      pFile:PChar;
    begin  
      FileName:='c:\abc';//这里是关键。
      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;
      

  4.   

    图标改成半透明的?这个你得处理消息
    LVM_SETITEMSTATE