MFC 多线程拷贝文件开始暂停停止和进度条

本文介绍了如何在MFC环境中使用多线程进行文件拷贝,并实现拷贝过程的开始、暂停、停止功能,同时结合进度条展示拷贝进度。通过头文件和cpp代码的详细说明,读者可以了解到具体的实现步骤和技术要点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如图建一个基于对话框

 

代码如下 一个头文件一个cpp

// CopyFileDlg.h : 头文件
//

#pragma once
#include "afxcmn.h"
#include "afxwin.h"
UINT MyThreadFun(LPVOID pParam);

// CCopyFileDlg 对话框
class CCopyFileDlg : public CDialog
{
// 构造
public:
	CCopyFileDlg(CWnd* pParent = NULL);	// 标准构造函数

// 对话框数据
	enum { IDD = IDD_COPYFILE_DIALOG };

	HANDLE hStop;
	HANDLE hExit;

   CWinThread * pThreadpause;
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持

	

// 实现
protected:
	HICON m_hIcon;

	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
	
public:
	
	CString m_srcPath;
	CString m_desPath;
	afx_msg void OnBnClickedButtonsrcpath();
	afx_msg void OnBnClickedButtondespath();
	afx_msg void OnBnClickedButtonstat();
	afx_msg void OnBnClickedButtonstop();
	afx_msg void OnBnClickedButtonpause();
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	CProgressCtrl m_ProgressCopy;
	afx_msg void OnDestroy();
    afx_msg LRESULT Do_process(WPARAM wParam,LPARAM lParam); 
	afx_msg LRESULT CCopyFileDlg::ShowFile(WPARAM wParam, LPARAM lParam); 
	

	CEdit m_EditShowName;
	int m_iStatus;
};

 

 

cpp

 

#include "stdafx.h"
#include "CopyFile.h"
#include "CopyFileDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
static int countset = 0;
#define WM_USER_PROCESS (WM_USER+100)
#define WM_USER_SHOW (WM_USER+101)
void myCopyDirectory(CString source, CString target,CWnd * pWndMsg);
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
void myCopyDirectory(CString source, CString target);  
VOID GetInfo(CString csPath, long& iDirCnt, long& iFileCnt);
//INT  myCount(CString source);
static  int nl
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值