📄 filespltdlg.cpp
字号:
// filespltDlg.cpp : implementation file
//
#include "stdafx.h"
#include "filesplt.h"
#include "filespltDlg.h"
#include "DirDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFilespltDlg dialog
CFilespltDlg::CFilespltDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFilespltDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFilespltDlg)
m_path1 = _T("");
m_path2 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFilespltDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFilespltDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_progress);
DDX_Control(pDX, IDC_COMBO1, m_combo);
DDX_Control(pDX, IDC_EDIT2, m_edit2);
DDX_Control(pDX, IDC_EDIT1, m_edit1);
DDX_Text(pDX, IDC_EDIT1, m_path1);
DDX_Text(pDX, IDC_EDIT2, m_path2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFilespltDlg, CDialog)
//{{AFX_MSG_MAP(CFilespltDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ONCANLE, OnOncanle)
ON_BN_CLICKED(IDC_START, OnStart)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFilespltDlg message handlers
BOOL CFilespltDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//装载位图按钮
VERIFY(m_1.AutoLoad(IDC_BUTTON2,this));
VERIFY(m_2.AutoLoad(IDC_BUTTON1,this));
VERIFY(m_3.AutoLoad(IDC_START,this));
VERIFY(m_4.AutoLoad(IDC_ONCANLE,this));
//初始化进度条
m_progress.SetRange(0,100);
m_progress.SetPos(0);
//初始化列表框
m_combo.SetCurSel(3);
return TRUE; // return TRUE unless you set the focus to a control
}
void CFilespltDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFilespltDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFilespltDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
UINT CFilespltDlg::getfilesize()
{
switch(m_combo.GetCurSel()){
case 3:
return 1.37*1024*1024;
case 2:
return 1.2*1020*1024;
case 1:
return 1*1020*1024;
case 0:
return 0.7*1024*1024;
default:
return 1.37*1024*1024;
}
}
BOOL CFilespltDlg::spltme()
{
UpdateData(true);
UINT len,newlen,l;
char buff[20];
char buffer[140000];
CString name,newfilepath,batpath;
newfilepath=m_path2;
l=1;
int deread;
CFile bat;
//定义代表回车的字符串
char enter[3];
enter[0]=0x0A;
enter[1]=0x0D;
enter[2]=0;
UpdateData(true);
newlen=getfilesize();
UINT ncount=newlen/100;//定义了一个小变量,以防读文件出错
if(m_path1=="")
{MessageBox("您还没选择待分割的文件","error");
return true;}
if(m_path2=="")
{MessageBox("请选择存放分割文件的文件夹","error");
return true;}
if(!sourcefile.Open(sourcefilepath,CFile::modeRead))
{ MessageBox("打开文件出错","error");
m_path1="";
m_path2="";
UpdateData(false);
sourcefile.Close();
return true;
}
if((len=sourcefile.GetLength())<newlen)
{
MessageBox("文件不够指定长度","error");
sourcefile.Close();
return true;
}
//指定进度条步长
n=100*newlen/len;
m_progress.SetStep(n);
if(newfilepath.Right(1)=="\\")
newfilepath=newfilepath.Left(strlen(newfilepath)-1);
//建立一个目录...
WIN32_FIND_DATA fdata;
HANDLE h;
h=FindFirstFile(newfilepath,&fdata);
if(fdata.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY);
else
CreateDirectory(newfilepath,NULL);
FindClose(h);
//建立一个批处理文件
newfilepath+=_T("\\");
bat.Open(newfilepath+sourcefile.GetFileTitle()+_T(".bat"),CFile::modeCreate|CFile::modeWrite);
batpath="copy/b ";
bat.Write(batpath,strlen(batpath));
//分割文件
do
{
CFile destfile;
name=_itoa(l,buff,10);
name+=_T("_");
if(!destfile.Open(newfilepath+name+sourcefile.GetFileName(),CFile::modeCreate|CFile::modeWrite))
{
MessageBox("文件分割出错","error");
m_path1="";
m_path2="";
UpdateData(false);
destfile.Close();
return true;
}
do{
deread=sourcefile.Read(buffer,ncount);
destfile.Write(buffer,deread);
}
while(deread>0&&(destfile.GetLength()<=newlen));
l++;
m_progress.StepIt();
batpath=name+sourcefile.GetFileName()+_T("+");
bat.Write(batpath,strlen(batpath));
destfile.Close();
}
while(deread>0);
m_progress.SetPos(0);//进度条回位0
bat.Seek(-1,CFile::end);//消去上面多加的"+"号
batpath=_T(" ")+sourcefile.GetFileName();
bat.Write(batpath,strlen(batpath));
//写入回车
bat.Write(enter,3);
batpath="exit";
bat.Write(batpath,strlen(batpath));
bat.Write(enter,3);
sourcefile.Close();
bat.Close();
return false;
}
void CFilespltDlg::OnOncanle()
{
// TODO: Add your control notification handler code here
OnOK();
}
void CFilespltDlg::OnStart()
{
// TODO: Add your control notification handler code here
BOOL error=spltme();
if(error)
{MessageBox("分割文件出错","error");
m_path1="";
m_path2="";
UpdateData(false);
}
else
{MessageBox("文件分割完毕","finish");
m_path1="";
m_path2="";
UpdateData(false);
}
}
void CFilespltDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(true,NULL,"*.*");
if(dlg.DoModal()==IDOK)
m_path1=sourcefilepath=dlg.GetPathName();
m_path2=dlg.GetFileExt();
m_path2=m_path1.Left(strlen(m_path1)-strlen(m_path2)-1)+_T("\\");
UpdateData(false);
}
void CFilespltDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CDirDialog dg;
dg.DoBrowse();
m_path2=dg.m_strPath;
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -