⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spillterdlg.cpp

📁 本产品为文本分割器
💻 CPP
字号:
// SpillterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Spillter.h"
#include "SpillterDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


#define KB 0
#define M 1
/////////////////////////////////////////////////////////////////////////////
// CSpillterDlg dialog
unsigned length, len;
CSpillterDlg::CSpillterDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSpillterDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSpillterDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_flag = 0;
	file_size = 0;
	m_brush.CreateSolidBrush(RGB(0,0,255));
}

void CSpillterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSpillterDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
	OnRadio_KB();
}

BEGIN_MESSAGE_MAP(CSpillterDlg, CDialog)
	//{{AFX_MSG_MAP(CSpillterDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnScan)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio_KB)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio_M)
	ON_BN_CLICKED(IDOK, OnIncise)
	ON_EN_CHANGE(IDC_EDIT3, OnFileSizeM)
	ON_BN_CLICKED(IDC_BUTTON2, OnSavePath)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSpillterDlg message handlers

BOOL CSpillterDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	
	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 CSpillterDlg::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);

		//CDialog::OnCtlColor);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSpillterDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSpillterDlg::OnScan() 
{
	// TODO: Add your control notification handler code here
	CFileDialog m_FileDialog(TRUE);
	
	if(m_FileDialog.DoModal() == IDOK)
	{
		m_flag = 1;
		m_OpenFileInfo = m_FileDialog.GetPathName();						//  
		m_SaveFileInfo = m_FileDialog.GetFileName();						
		m_OpenFileName = m_FileDialog.GetFileTitle();						//  文件标题
		
		int i = 0;
		while(m_SaveFileInfo.GetAt(i) != '.' && i < m_SaveFileInfo.GetLength())
		{
			i++;
		}
		if(i != m_SaveFileInfo.GetLength())
		{
			m_expan.Empty();
			do
			{
				m_expan += m_SaveFileInfo.GetAt(i);								//   获取扩展名
				i++;
			}while(i < m_SaveFileInfo.GetLength());
		}
		
		{
			CFileStatus status;
			CFile::GetStatus(m_OpenFileInfo.GetBuffer(0), status);
			
			file_size = status.m_size;
		}
		
		SetDlgItemText(IDC_EDIT1, m_OpenFileInfo.GetBuffer(0));				//  写入编辑框
		
		long M_size;
		M_size = file_size / (1024 * 1024);
		file_size = file_size % (1024 * 1024);
		SetDlgItemText(IDC_EDIT3, ChangeIntToChar(M_size).GetBuffer(0));
		file_size = file_size / 1024;
		SetDlgItemText(IDC_EDIT4, ChangeIntToChar(file_size).GetBuffer(0));

	}
}

void CSpillterDlg::OnRadio_KB() 
{
	// TODO: Add your control notification handler code here
	//MessageBox("","", MB_OK);
	m_unit = KB;
}

void CSpillterDlg::OnRadio_M() 
{
	// TODO: Add your control notification handler code here
	m_unit = M;
}



void CSpillterDlg::OnIncise()				//   切割
{
	// TODO: Add your control notification handler code here
	
	FILE *pOpen;
	FILE *pSave;
	long file_size = GetDlgItemInt(IDC_EDIT2);
	int file_num = 1;
	BOOL flag = 1;
	CString read_str;
	CString path;					//     路径信息1301770044YANG

	CFileException e, r;
	CString SaveFileInfo;

	if(!m_flag)
	{
		MessageBox("选择文件","WARNING!",MB_OK);
		return;
	}

	if(file_size == 0)
	{
		AfxMessageBox("请设置大小!");
		return;
	}
	m_OpenFile.Open(m_OpenFileInfo.GetBuffer(0), CFile::modeRead, &e);
	/////////////////////////////   获取路径
	{
		path = m_OpenFileInfo;
		path.Delete(m_OpenFileInfo.GetLength() - m_OpenFileName.GetLength() - m_expan.GetLength(), m_OpenFileName.GetLength() + m_expan.GetLength());
	}

	if(m_unit == M )
		file_size *= 1024;

	SaveFileInfo = path + m_OpenFileName + ChangeIntToChar(file_num) + m_expan;
	int i;
	while(flag)
	{
		i = 0;
		m_TempFile.Open(SaveFileInfo, CFile::modeCreate | CFile::modeWrite, &r);
		while(flag && i < file_size)
		{
			read_str = GetText(flag, file_size);
			m_TempFile.Write(read_str, length);
			i++;
		}
		m_TempFile.Close();
		SaveFileInfo.Empty();
		file_num ++;
		SaveFileInfo = path  + m_OpenFileName + ChangeIntToChar(file_num) + m_expan;
	}
	m_OpenFile.Close();
	MessageBox("分割完毕","OK",MB_OK);

}

void CSpillterDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}



CString CSpillterDlg::ChangeIntToChar(unsigned num)
{
	long k = 10;
	CString str;

	while(num > 0)
	{
		str.Insert(0,num % k + 48);
		num = num / k;
	}
	return str;
}

CString CSpillterDlg::GetText(int &flag, long file_size)
{
	CString str;
	char * buffer = new char [1025];
	
	length = m_OpenFile.Read(buffer, 1024);
	buffer[length + 1] = '\0';
	str += buffer;
	
	if(length < 1024)
	{
		flag = 0;
	}
	
	return str;
}


void CSpillterDlg::OnFileSizeM() 
{	
}

void CSpillterDlg::OnFileSizeKB() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	long KB_size;
	KB_size = file_size / 1024;
	SetDlgItemText(IDC_EDIT4, ChangeIntToChar(KB_size));  
}

void CSpillterDlg::OnSavePath() 
{
	// TODO: Add your control notification handler code here

	return;	
}

void CSpillterDlg::SetColor()
{
//	CDialog::OnCtlColor();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -