檔案複製過程中顯示進度條 九

2021-04-15 11:16:02 字數 2981 閱讀 4109

檔案複製過程中顯示進度條(九

) 本文講述如何在檔案複製過程中顯示進度條。 1.

建立乙個對話方塊工程:

copyfileprocessor 2.

新增乙個文字框,用來顯示瀏覽出來的原始檔路徑,新增乙個按鈕「瀏覽」,來選擇原始檔,如下:

cfiledialog

log(

true,"

檔案","*.*"

,ofn_hidereadonly

,"file(*.*)|*.*||"

,null);

if(log.

domodal

()==

idok)

3.新增乙個文字框來顯示瀏覽出來的目標存放路徑,新增乙個按鈕「瀏覽」,來選擇目標存放路徑,如下: if

(strname

.isempty

())

return;

browseinfo

bi;  

char

buffer

[max_path

];  

zeromemory

(buffer

,max_path

);   bi

.hwndowner

=getsafehwnd

();   bi

.pidlroot

=null

;   bi

.pszdisplayname

=buffer

;   bi

.lpsztitle="

選擇乙個資料夾

";   bi

.ulflags

=bif_editbox

;   bi

.lpfn

=null

;   bi

.lparam

=0;   bi

.iimage

=0;

lpitemidlist

plist

=null

;   if

((plist

=shbrowseforfolder

(&bi

))!=

null

)  

4. 新增乙個進度條控制項,新增乙個按鈕「複製」,**如下: if

(pathname

.isempty

())

return;

if(fullname

.isempty

())

return;

readfile

= new

cfile

(pathname

,cfile

::moderead);

handle

hfile

= ::

createfile

(fullname

,generic_write

|generic_read

,0,0,

create_new

,file_attribute_normal

,0);

closehandle

(hfile);

writefile

= new

cfile

(fullname

,cfile

::modewrite);

filelen

= readfile

->

getlength

();

ldiv_tr;

r= ldiv

(filelen

,100);

long

pos= r.

quot;

long

ipos;

ipos

= pos;

inti

= 0;

hglobal

= globalalloc

(gmem_moveable

,512);

pvdata

= globallock

(hglobal);

while

(1)

m_fileproc

.setpos(i

); m_fileproc

.invalidate

();

writefile

->

writehuge

(pvdata

,readlen);

if(poslen

== filelen)

break;

} afxmessagebox("

複製完成");

m_fileproc

.setpos

(0);

globalunlock

(hglobal);

readfile

->

close

();

writefile

->

close

();

注意,其中有些變數的宣告如下:

cstring

strname;

cstring

fullname;

cstring

pathname;

hglobal

hglobal;

cfile

* writefile;

cfile

* readfile;

long

readlen

,poslen

,filelen;

lpvoid

pvdata;

並在建構函式中初始化,如下:

readfile

= null;

writefile

= null;

pvdata

= null;

完成。

使用C 在進度條中顯示複製檔案的進度

public class frmmain system.windows.forms.form 清理所有正在使用的資源。protected override void dispose bool disposing base.dispose disposing region initialize com...

使用C 在進度條中顯示複製檔案的進度

region using directives using system using system.io using system.xml using system.collections using system.reflection using system.text using system....

使用C 在進度條中顯示複製檔案的進度

region using directives using system using system.io using system.xml using system.collections using system.reflection using system.text using system....