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

📄 comppage.cpp

📁 对文件进行处理。 包括文件复制、分割、连接、查看等。
💻 CPP
字号:
// CompPage.cpp : implementation file
//

#include "stdafx.h"
#include "Made.h"
#include "CompPage.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "OutDlg.h"

/////////////////////////////////////////////////////////////////////////////
// CCompPage property page
UINT CompPro(LPVOID pParam)
{
	CCompPage * dlg=(CCompPage * )pParam;
	dlg->Comp();
	dlg->GetDlgItem(IDC_COMP)->EnableWindow(1);
	dlg->GetDlgItem(IDC_COMP_LOOK1)->EnableWindow(1);
	dlg->GetDlgItem(IDC_COMP_LOOK2)->EnableWindow(1);
	dlg->GetDlgItem(IDC_COMP_FILE1)->EnableWindow(1);
	dlg->GetDlgItem(IDC_COMP_FILE2)->EnableWindow(1);
	dlg->GetDlgItem(IDC_COMP_STOP)->EnableWindow(0);
	dlg->m_Progress.SetPos(0);
	dlg->m_BreakFlag=0;
	fcloseall();
	return 0;
}
IMPLEMENT_DYNCREATE(CCompPage, CPropertyPage)

CCompPage::CCompPage() : CPropertyPage(CCompPage::IDD)
{
	//{{AFX_DATA_INIT(CCompPage)
	//}}AFX_DATA_INIT
}

CCompPage::~CCompPage()
{
}

void CCompPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCompPage)
	DDX_Control(pDX, IDC_COMP_PROGRESS, m_Progress);
	DDX_Control(pDX, IDC_COMP_FILE2, m_File2);
	DDX_Control(pDX, IDC_COMP_FILE1, m_File1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCompPage, CPropertyPage)
	//{{AFX_MSG_MAP(CCompPage)
	ON_BN_CLICKED(IDC_COMP, OnComp)
	ON_BN_CLICKED(IDC_COMP_STOP, OnCompStop)
	ON_BN_CLICKED(IDC_COMP_OUT, OnCompOut)
	ON_BN_CLICKED(IDC_COMP_LOOK1, OnCompLook1)
	ON_BN_CLICKED(IDC_COMP_LOOK2, OnCompLook2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCompPage message handlers

void CCompPage::OnComp() 
{
	// TODO: Add your control notification handler code here
	CString str;
	m_File1.GetWindowText(str);
	if(str.IsEmpty())
	{
		MessageBox("文件1不能为空!","空文件",MB_ICONERROR);
		GetDlgItem(IDC_COMP_FILE1)->SetFocus();
		return;
	}
	m_File2.GetWindowText(str);
	if(str.IsEmpty())
	{
		MessageBox("文件2不能为空!","空文件",MB_ICONERROR);
		GetDlgItem(IDC_COMP_FILE2)->SetFocus();
		return;
	}
	GetDlgItem(IDC_COMP)->EnableWindow(0);
	GetDlgItem(IDC_COMP_LOOK1)->EnableWindow(0);
	GetDlgItem(IDC_COMP_LOOK2)->EnableWindow(0);
	GetDlgItem(IDC_COMP_FILE1)->EnableWindow(0);
	GetDlgItem(IDC_COMP_FILE2)->EnableWindow(0);
	GetDlgItem(IDC_COMP_STOP)->EnableWindow(1);
	m_BreakFlag=0;
	AfxBeginThread(CompPro,this);
}

void CCompPage::OnCompStop() 
{
	m_BreakFlag=1;
	fcloseall();
}

void CCompPage::OnCompOut() 
{
	COutDlg dlg;
	dlg.lpvoid=(DWORD)this;
	dlg.DoModal();
}

int CCompPage::Comp()
{
	CString name1,name2;
	m_File1.GetWindowText(name1);
	m_File2.GetWindowText(name2);
	FILE * p1,*p2;
	if((p1=fopen(name1,"rb"))==NULL)
	{
		MessageBox("不能打开文件1!","打开文件错误",MB_ICONERROR);
		fcloseall();
		return 0;
	}
	if((p2=fopen(name2,"rb"))==NULL)
	{
		MessageBox("不能打开文件2!","打开文件错误",MB_ICONERROR);
		fcloseall();
		return 0;
	}
	GetDlgItem(IDC_COMP_OUT)->EnableWindow(1);
	m_Progress.SetRange(0,1000);
	L_File1=filelength(p1->_file);
	L_File2=filelength(p2->_file);
	DWORD LFile=(L_File1<L_File2)?L_File1:L_File2;
	int ShowProgress=LFile/1000;
	for(int nIndex=m_Word.GetSize()-1;nIndex>=0;nIndex--)
		delete m_Word.GetAt(nIndex);
	m_Word.RemoveAll();
	char buf1[NUM],buf2[NUM];
	for(int Index=0;Index<(int)(LFile/NUM);Index++)
	{
		if(m_BreakFlag)return 0;
		fread(buf1,NUM,1,p1);
		fread(buf2,NUM,1,p2);
		for(int i=0;i<NUM;i++)
			if(buf1[i]!=buf2[i])
			{
				CWord * word=new(CWord);
				word->c1=buf1[i];
				word->c2=buf2[i];
				word->sit=Index*NUM+i+1;
				m_Word.Add(word);
			}
		m_Progress.SetPos(ftell(p1)/ShowProgress);
	}
	int Times=LFile-ftell(p1);
	fread(buf1,Times,1,p1);
	fread(buf2,Times,1,p2);
	for(int i=0;i<Times;i++)
		if(buf1[i]!=buf2[i])
		{
			CWord * word=new(CWord);
			word->c1=buf1[i];
			word->c2=buf2[i];
			word->sit=Index*NUM+i+1;
			m_Word.Add(word);
		}
	return 0;
}

void CCompPage::OnCompLook1() 
{
	CFileDialog m_file_dlg(1);
	if(m_file_dlg.DoModal()==IDOK)
		m_File1.SetWindowText(m_file_dlg.GetPathName());
}

void CCompPage::OnCompLook2() 
{
	CFileDialog m_file_dlg(1);
	if(m_file_dlg.DoModal()==IDOK)
		m_File2.SetWindowText(m_file_dlg.GetPathName());
}

BOOL CCompPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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