📄 filespltdlg.cpp
字号:
// FileSpltDlg.cpp : implementation file
//
//Modify by 徐景周 ,2001.2.13
//功能:文件分割为各种大小格式,并将其合并在一起
//
#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 };
CWBButton m_OK;
//}}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)
virtual BOOL OnInitDialog();
//}}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)
DDX_Control(pDX, IDOK, m_OK);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileSpltDlg dialog
CFileSpltDlg::CFileSpltDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileSpltDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileSpltDlg)
m_parts = _T("状态显示");
m_path = _T("");
m_targetpath = _T("");
m_split = TRUE;
//}}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_COMBOX_FILESIZE, m_FileSize);
DDX_Control(pDX, IDC_PROGRESS, pProgress);
DDX_Control(pDX, IDC_BUTTON_MERGE, m_buttMerge);
DDX_Control(pDX, IDCANCEL, m_buttExit);
DDX_Control(pDX, IDOK, m_buttSplit);
DDX_Control(pDX, IDC_BROWSE, m_Browse);
DDX_Control(pDX, IDC_BROWSE2, m_Browse2);
DDX_Control(pDX, IDC_RADIO3, m_RadioSplit);
DDX_Control(pDX, IDC_PATH, m_edit);
DDX_Text(pDX, IDC_PARTS, m_parts);
DDX_Text(pDX, IDC_PATH, m_path);
DDX_Text(pDX, IDC_PATH2, m_targetpath);
//}}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_BROWSE, OnBrowse)
ON_BN_CLICKED(IDOK, OnOk)
ON_BN_CLICKED(IDC_BUTTON_MERGE, OnButtonMerge)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_BROWSE2, OnBrowse2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileSpltDlg message handlers
BOOL CFileSpltDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if (m_split)
m_RadioSplit.SetCheck(1);
CButton *pButtonMerge = (CButton*)(GetDlgItem(IDC_BUTTON_MERGE));
pButtonMerge->EnableWindow(FALSE);
m_path =_T("");
m_filename =_T("");
// 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
//设置位图按钮
m_Browse.LoadBitmaps(IDB_BITMAP2,6, 1, 1, 1, 1 );
m_Browse.SetFontColor(RGB(240,200,90));
m_Browse2.LoadBitmaps(IDB_BITMAP2,6, 1, 1, 1, 1 );
m_Browse2.SetFontColor(RGB(240,200,90));
m_buttExit.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_buttMerge.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_buttSplit.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
//在此初始化渐变色进度条
pProgress.SetRange32(1,500);
pProgress.SetBkColor(RGB(160,180,220));
pProgress.ShowPercent(true);
pProgress.SetPos(500);
//设置选择文件大小下拉框默认值为第1个
m_FileSize.SetCurSel(0);
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::GetSplitFileSize()
{
switch(m_FileSize.GetCurSel())
{
case 0:
return 1400000;
case 1:
return 1200000;
case 2:
return 1000000;
case 3:
return 800000;
default:
return 1400000;
}
}
// 文件合并涵数
int CFileSpltDlg::MergeMe()
{
CWaitCursor wait;
// constructing these file objects
CFile destFile;
// we'll use a CFileException object to get error information
CFileException ex;
BYTE buffer[140000];
DWORD dwRead;
UINT nCount = 140000;
UINT newlen = 1400000;
char buff [20];
long l = 1;
CString name;
CString pref;
CString newpath;
UpdateData(TRUE);
//open file for read
if (!m_path.IsEmpty()) {
if (!m_SourceFile.Open(m_path, CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary, &ex)) {
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
::AfxMessageBox(szError);
m_edit.SetFocus();
m_edit.SetSel(0, -1);
return 1;
}
//construct new name
m_filename = m_path.Right((m_path.GetLength() - m_path.ReverseFind('\\')) - 1);
//close file
m_SourceFile.Close();
}
//constuct a new path name
newpath = m_path.Left(m_path.GetLength() - m_filename.GetLength());
if (!m_targetpath.IsEmpty()) {
//some silly check, that could be chnged
if (!m_filename.IsEmpty() && m_filename.Left(2) != _T("1_")) {
::AfxMessageBox(_T("待合并的源文件名不对..."), MB_ICONERROR);
return 1;
}
else if(m_filename.IsEmpty()) {
MessageBox(_T("请选择待合并的源文件."), _T("文件分割器"), MB_ICONEXCLAMATION);
return 1;
}
//constuct an original file name
m_filename = m_filename.Right(m_filename.GetLength() - 2);
//判断选择目录未尾是否已有"\"符
if(m_targetpath.Right(1)=='\\')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -