📄 +-+
字号:
if (temp == (unsigned int)(srcFile.GetLength()*0.85)) m_ProgressCTRL.SetPos(90);
if (temp == (unsigned int)(srcFile.GetLength()*0.90)) m_ProgressCTRL.SetPos(95);
if (temp == (unsigned int)(srcFile.GetLength()*0.95)) m_ProgressCTRL.SetPos(98);
if (temp == (unsigned int)(srcFile.GetLength()*1)) m_ProgressCTRL.SetPos(100);
}
HCURSOR CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//“关于”对话框 100%
void CMyDlg::OnButtonAboutme()
{
CAboutDlg TheAboutDlg;
TheAboutDlg.DoModal();
}
//如果“源文件”EDIT BOX获得焦点 100%
void CMyDlg::OnSetfocusEditSourcefile()
{//改变提示
UpdateData(TRUE);
m_sReportContext = "输入源文件路径和名称";
UpdateData(FALSE);
}
//如果“目标目录”EDIT BOX 获得焦点 100%
void CMyDlg::OnSetfocusEditTagfile()
{//改变提示
UpdateData(TRUE);
m_sReportContext = "输入目标目录全称";
UpdateData(FALSE);
}
//点击“分割文件”按钮 100%
void CMyDlg::OnRadioCutfile()
{ if ( Check == 0 ) return ; //如果标识值为则跳出
Check = 1 ; //置标识值为1,即分割
m_sReportContext = "请在上面输入要分割的'源文件名'和'目标目录'";
ActiveItem(true) ; //打开"执行区"控件
UpdateData(false); //更新一下
}
//点击“合并文件”按钮 100%
void CMyDlg::OnRadioUnitdfile()
{ if ( Check == 0 ) return ; //如果标识值为则跳出
Check = 2 ; //置标识值为2,即合并
m_sReportContext = "请在上面输入要合并的'源文件名'和'目标目录'";
ActiveItem(true) ; //打开"执行区"控件
UpdateData(false); //更新一下
}
//“浏览” --源文件 100%
void CMyDlg::OnButtonSourcefilebrowse()
{//检测Check值,根据Check值进行操作
//生成一个选择分割文件对话框
CFileDialog ChoiceCutFile(true,NULL,NULL,OFN_HIDEREADONLY,"所有文件|*.*",NULL);
ChoiceCutFile.m_ofn.lpstrTitle="请选择一个要分割的文件";
ChoiceCutFile.m_ofn.lpstrInitialDir=".";
//生成一个选择合并文件对话框
CFileDialog ChoiceUnitdFile(true,NULL,NULL,OFN_HIDEREADONLY,"分割头文件|*.cut1",NULL);
ChoiceUnitdFile.m_ofn.lpstrTitle="请选择一个头文件";
ChoiceUnitdFile.m_ofn.lpstrInitialDir=".";
switch (Check) {
case (1) : //如果选择了分割文件
if (ChoiceCutFile.DoModal() == IDCANCEL) return;
m_eSrcFile = ChoiceCutFile.GetPathName();
break;
case (2) : //如果选择了合并文件
if (ChoiceUnitdFile.DoModal() == IDCANCEL) return;
m_eSrcFile = ChoiceUnitdFile.GetPathName();
break;
default : //什么都不是
int TheResult = MessageBox("程序发生意外错误!\n 关闭吗?","异教徒工作室 InfidelStudio",MB_YESNO+MB_ICONSTOP);
if (TheResult == IDYES)
SendMessage(WM_CLOSE,0,0); //关闭程序
break;
}
UpdateData(FALSE); //更新一下
}
//“浏览” --目标目录 100%
void CMyDlg::OnButtonTagfilebrowse()
{//检测Check值,根据Check值进行更新
CDirDialog ChoiceFolder;
switch (Check) {
case (1) : //如果选择了分割文件
ChoiceFolder.DoBrowse(this);
m_eTagFile = ChoiceFolder.m_strPath;
break;
case (2) : //如果选择了合并文件
ChoiceFolder.DoBrowse(this);
m_eTagFile = ChoiceFolder.m_strPath;
break;
default : //什么都不是
int TheResult = MessageBox("程序发生意外错误!\n 关闭吗?","异教徒工作室 InfidelStudio",MB_YESNO+MB_ICONSTOP);
if (TheResult == IDYES)
SendMessage(WM_CLOSE,0,0); //关闭程序
break;
}
UpdateData(FALSE); //更新一下
}
//点击“执行”按钮 90%
void CMyDlg::OnButtonRun()
{//首先检测“源文件名”和“目标目录”
UpdateData(true); //更新一下
if (m_eSrcFile == "") {
MessageBox("请输入源文件名",NULL,MB_OK+MB_ICONINFORMATION);
return;}
if (m_eTagFile == "") {
MessageBox("请输入目标目录",NULL,MB_OK+MB_ICONINFORMATION);
return;}
CMyApp* app = (CMyApp*)AfxGetApp(); //准备调用全局变量
//生成一个显示输入对话框
CInputDialog IPDialog;
//检测Check值,根据Check值进行操作
switch (Check) {
case (1) ://如果为“分割文件”
//打开文件
if (!srcFile.Open(m_eSrcFile,CFile::modeRead|CFile::typeBinary,NULL))
{MessageBox("读源文件出错!","错误",MB_OK+MB_ICONSTOP);srcFile.Close();return;}
//获得待分割文件的长度dwLongOfSourceFile
dwLongOfSourceFile = srcFile.GetLength();
//显示输入分割文件大小对话框
TempStr = srcFile.GetFileName();
IPDialog.ChangeReport(Check,srcFile.GetFileName(),dwLongOfSourceFile,TempStr.Right(4));
if (IPDialog.DoModal() == IDCANCEL) //如果点击“取消”
{srcFile.Close();return;}
//更新分割文件的长度
dwLongOfCutFile = app->TempFileSize;
//分割操作(用m_ProgressCTRL和m_sReportContext表示)
//tagFileName表示目标文件名,FileNum文件数
FileNum = 1 ;
srcFile.SeekToBegin();
do {
tagExtName.Format(".cut%d",FileNum);
//tagFileName = tagFileName.Left((tagFileName.GetLength()-4)) + tagExtName;
tagFileName = m_eTagFile + "\\" + srcFile.GetFileName() + tagExtName ;
if (!tagFile.Open(tagFileName,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary,NULL)) {
MessageBox("无法分割文件","错误",MB_OK+MB_ICONSTOP);return;}
FileNum++; //文件数加1
//进行提示更新
m_sReportContext = "正在分割.... 当前处理文件:" + tagFile.GetFileName();
UpdateData(FALSE);
for (temp=1;temp <= dwLongOfCutFile;temp++) {
if (!srcFile.Read(&Context,sizeof(Context))) {
//如果读文件出错--文件结束
m_ProgressCTRL.SetPos(100);
m_sReportContext = "完成!";
UpdateData(FALSE);
srcFile.Close();tagFile.Close();return;}
else {
tagFile.Write(&Context,sizeof(Context));}
//进行进度条更新
UpdateProgress();
}
//关闭目标文件
m_ProgressCTRL.SetPos(100);m_sReportContext = "完成!";
UpdateData(FALSE);
tagFile.Close();
}while (srcFile.GetLength() != srcFile.GetPosition());
break;
case (2) ://如果为“合并文件”
//打开文件
if (!srcFile.Open(m_eSrcFile,CFile::modeRead|CFile::typeBinary,NULL))
{MessageBox("读源文件出错!","错误",MB_OK+MB_ICONSTOP);srcFile.Close();return;}
//进行判断
TempStr = srcFile.GetFileName();
if (TempStr.Right(4) != "cut1")
{MessageBox("不是头文件!","错误",MB_OK+MB_ICONSTOP);srcFile.Close();return;}
//得到合并文件扩展名
srcFileName = srcFile.GetFileName();srcFileName = srcFileName.Right(8);tagExtName = srcFileName.Left(4);
//得到合并文件主文件名
srcFileName = srcFile.GetFileName();srcFileName = srcFileName.Left(srcFileName.GetLength()-8);
//得到合并文件的全名
tagFileName = m_eTagFile + "\\" + srcFileName + tagExtName;
//打开合并文件
if (!tagFile.Open(tagFileName,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary,NULL)) {
MessageBox("无法合并文件","错误",MB_OK+MB_ICONSTOP);return;}
FileNum = 1 ;
do {
FileNum++; //文件数加1
//进行提示更新
m_sReportContext = "正在合并.... 当前处理文件:" + srcFile.GetFileName();
UpdateData(FALSE);
for (temp=1;temp <= srcFile.GetLength();temp++) {
srcFile.Read(&Context,sizeof(Context));
tagFile.Write(&Context,sizeof(Context));
//进行进度条更新
UpdateProgress2();
}
srcFileName = srcFile.GetFileName();
tagExtName.Format("cut%d",FileNum);
srcFileName = srcFileName.Left((srcFileName.GetLength()-4)) + tagExtName;
srcFile.Close();
if (!srcFile.Open(srcFileName,CFile::modeRead|CFile::typeBinary,NULL)) {FileNum = -1;}
}while (FileNum != -1);
//关闭文件
m_sReportContext = "完成!";UpdateData(FALSE);
tagFile.Close();
srcFile.Close();
break;
default ://如果都不是(意外错误)
int TheResult = MessageBox("程序发生意外错误!\n 关闭吗?","异教徒工作室 InfidelStudio",MB_YESNO+MB_ICONSTOP);
if (TheResult == IDYES)
SendMessage(WM_CLOSE,0,0); //关闭程序
break;
}
//结束部分
srcFile.Close(); //关闭源文件
tagFile.Close(); //关闭目标文件
}
void CMyDlg::OnMenuitemF()
{
// TODO: Add your command handler code here
OnRadioCutfile();
}
void CMyDlg::OnMenuitemH()
{
// TODO: Add your command handler code here
OnRadioUnitdfile();
}
void CMyDlg::OnMenuiteB()
{
// TODO: Add your command handler code here
OnButtonAboutme();
}
void CMyDlg::OnMenuitemZ()
{
// TODO: Add your command handler code here
OnButtonRun();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -