求CopyFileEx 使用的例子~~~(100分)

  • 主题发起人 主题发起人 new水水
  • 开始时间 开始时间
N

new水水

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢哦!~~!~!~
 
简单的使用<br>CopyFileEx('c:/ts_tm.xml','d:/ts_tm.xml',nil,nil,pbool(False),1);<br>参数太多,我打了。
 
手头没有NT,大概是这样的。。。<br>unit Unit6;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>const<br>&nbsp; WM_COPYFILE = WM_USER + 1;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; procedure WMCOPYFILE(var Msg: TMessage); message WM_COPYFILE;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>function CopyProgress(<br>&nbsp; TotalFileSize &nbsp; &nbsp; &nbsp; &nbsp; : LARGE_INTEGER; &nbsp;// total file size, in bytes<br>&nbsp; TotalBytesTransferred : LARGE_INTEGER; &nbsp;// total number of bytes transferred<br>&nbsp; StreamSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: LARGE_INTEGER; &nbsp;// total number of bytes for this stream<br>&nbsp; StreamBytesTransferred: LARGE_INTEGER; &nbsp;// total number of bytes transferred for this stream<br>&nbsp; dwStreamNumber &nbsp; &nbsp; &nbsp; &nbsp;: DWORD; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// the current stream<br>&nbsp; dwCallbackReason &nbsp; &nbsp; &nbsp;: DWORD; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// reason for callback<br>&nbsp; hSourceFile &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : THANDLE; &nbsp; &nbsp; &nbsp; &nbsp;// handle to the source file<br>&nbsp; hDestinationFile &nbsp; &nbsp; &nbsp;: THANDLE; &nbsp; &nbsp; &nbsp; &nbsp;// handle to the destination file<br>&nbsp; lpData &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Pointer &nbsp; &nbsp; &nbsp; &nbsp; // passed by CopyFileEx<br>&nbsp; ) : DWORD; stdcall;<br>var<br>&nbsp; S : String;<br>begin<br>&nbsp; S := Format('%08X:%08X of %08X:%08X copied./', [TotalBytesTransferred.HighPart,TotalBytesTransferred.LowPart,TotalFileSize.HighPart,TotalFileSize.LowPart]);<br>&nbsp; PostMessage(Form1.Handle, WM_COPYFILE, 0, Integer(PChar(S)));<br>&nbsp; Result := PROGRESS_CONTINUE;<br>end;<br><br>procedure TForm1.WMCOPYFILE(var Msg: TMessage);<br>begin<br>&nbsp; Label1.Caption := PChar(Msg.LParam);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; Cancel &nbsp; &nbsp;: Bool;<br>&nbsp; Src, Dest : String;<br>begin<br>&nbsp; Cancel := False;<br>&nbsp; Src := 'c:/yyy';<br>&nbsp; Dest:= 'c:/xxx';<br>&nbsp; CopyFileEx(PChar(Src), PChar(Dest), @CopyProgress, nil, @Cancel,COPY_FILE_FAIL_IF_EXISTS)<br>end;<br><br>end.<br>
 
多人接受答案了。
 
后退
顶部