【VC开源代码栏目提醒】:网学会员VC开源代码为您提供FilePartitionDlg.cpp参考,解决您在FilePartitionDlg.cpp学习中工作中的难题,参考学习。
// FilePartitionDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FilePartition.h"
#include "FilePartitionDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFilePartitionDlg dialog
CFilePartitionDlg::CFilePartitionDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFilePartitionDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFilePartitionDlg)
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFilePartitionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFilePartitionDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFilePartitionDlg, CDialog)
//{{AFX_MSG_MAP(CFilePartitionDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTADD, OnAdd)
ON_BN_CLICKED(IDC_BTDIR, OnAddDir)
ON_BN_CLICKED(IDC_BTPatition, OnPartition)
ON_BN_CLICKED(IDC_BTSELPART, OnSelectPart)
ON_BN_CLICKED(IDC_BTOMBIN, OnOmbin)
ON_EN_CHANGE(IDC_EDFILEPATH, OnChangeEdfilepath)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFilePartitionDlg message handlers
BOOL CFilePartitionDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CFilePartitionDlg::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();
}
}
HCURSOR CFilePartitionDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFilePartitionDlg::OnAdd()
{
CFileDialog log(TRUE,NULL,NULL,OFN_HIDEREADONLY,"FILE(*.*)|*.*||",NULL);
if(log.DoModal()==IDOK)
{
CString pathname;
pathname=log.GetPathName();
filename=log.GetFileName();
filenamenoext=log.GetFileTitle();
filenameext=log.GetFileExt();
GetDlgItem(IDC_EDFILEPATH)->SetWindowText(pathname);
CFileStatus status;
CFile::GetStatus(pathname,status);
CString strsize;
strsize.Format("文件大小为:%dBytes",status.m_size);
GetDlgItem(IDC_FILESIZE)->SetWindowText(strsize);
}
}
void CFilePartitionDlg::OnAddDir()
{
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)
{
char path[MAX_PATH];
ZeroMemory(path,MAX_PATH);
SHGetPathFromIDList(pList,path);
GetDlgItem(IDC_EDSAVEPATH)->SetWindowText(path);
}
}
void CFilePartitionDlg::OnPartition()
{
CFile *readfile,*writefile;
DWORD filelen,readlen,poslen;
CString name,path,desname;
//获得将要分割的文件的全路径
GetDlgItem(IDC_EDFILEPATH)->GetWindowText(name);
//获得分割后文件的存放路径
GetDlgItem(IDC_EDSAVEPATH)->GetWindowText(path);
CString strsize;
//获得文件分割块的大小
GetDlgItem(IDC_EDSIZE)->GetWindowText(strsize);
if(strsize.IsEmpty())return;
DWORD partsize=atoi(strsize)*1024;
BYTE *b=new BYTE[partsize];
readfile=new CFile(name,CFile::modeRead);
filelen=readfile->GetLength();
int i=1;
//在循环中根据文件的大小和用户设定的大小创建若干文件,并向文件中写入数据
while(1)
{
ZeroMemory(b,partsize);
desname.Format("%s\\%spart%d_%s.dat",path,filenamenoext,i,filenameext);
//创建文件块
HANDLE hfile=::CreateFile(desname,GENERIC_WRITE|GENERIC_WRITE,
0,0,CREATE_NE