📄 anandlg.cpp
字号:
// ANANDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ANAN.h"
#include "ANANDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
struct LineList
{
char szline[1024] ;
LineList * next;
};
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()
/////////////////////////////////////////////////////////////////////////////
// CANANDlg dialog
CANANDlg::CANANDlg(CWnd* pParent /*=NULL*/)
: CDialog(CANANDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CANANDlg)
m_Browse1 = _T("");
m_Browse2 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CANANDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CANANDlg)
DDX_Text(pDX, IDC_File1, m_Browse1);
DDX_Text(pDX, IDC_File2, m_Browse2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CANANDlg, CDialog)
//{{AFX_MSG_MAP(CANANDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_Browse1, OnBrowse1)
ON_BN_CLICKED(IDC_Browse2, OnBrowse2)
ON_BN_CLICKED(IDC_DLfile1, OnDLfile1)
ON_BN_CLICKED(IDC_DLfile2, OnDLfile2)
ON_BN_CLICKED(IDC_DLfile3, OnDLfile3)
ON_EN_CHANGE(IDC_File1, OnChangeFile1)
ON_EN_CHANGE(IDC_File2, OnChangeFile2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CANANDlg message handlers
BOOL CANANDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CANANDlg::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 CANANDlg::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 CANANDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CANANDlg::OnBrowse1()
{
// TODO: Add your control notification handler code here
char szFileters[]="Text fiels(*.txt)";
CFileDialog opendlg(TRUE,"txt","*.txt",OFN_FILEMUSTEXIST ,szFileters,this);
if (opendlg.DoModal()==IDOK)
{
m_Browse1=opendlg.GetPathName();
UpdateData(FALSE);
}
}
void CANANDlg::OnBrowse2()
{
// TODO: Add your control notification handler code here
char szFileters[]="Text fiels(*.txt)";
CFileDialog opendlg(TRUE,"txt","*.txt",OFN_FILEMUSTEXIST,szFileters,this);
if (opendlg.DoModal()==IDOK)
{
m_Browse2=opendlg.GetPathName();
UpdateData(false);
}
}
void CANANDlg::OnDLfile1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (m_Browse1=="")
{
return;
}
if (m_Browse2=="")
{
return;
}
CStdioFile f1;
CStdioFile f2;
if (!f1.Open(m_Browse1,CFile::modeReadWrite))
{
AfxMessageBox("文件没有找到或格式错误!");
return;
}
if (!f2.Open(m_Browse2,CFile::modeReadWrite))
{
AfxMessageBox("文件没有找到或格式错误!");
return;
}
char szOneline[1024] = {0};
LineList * lpszline=new LineList;
LineList * lpsznew=lpszline;
lpszline->next=NULL;
while (f1.ReadString(szOneline,1024))
{
int i=strlen(szOneline);
if (szOneline[i-1]=='\n')
{
szOneline[i-1]='\0';
}
lpsznew->next=new LineList;
lpsznew=lpsznew->next;
strcpy(lpsznew->szline,szOneline);
}
lpsznew->next=NULL;
char szOnelinef2[1024]={0};
while (f2.ReadString(szOnelinef2,1024))
{
int i=strlen(szOnelinef2);
if (szOnelinef2[i-1]=='\n')
{
szOnelinef2[i-1]='\0';
}
lpsznew=lpszline->next;
while (lpsznew)
{
if(strcmp(lpsznew->szline,szOnelinef2)==0)
{
strcpy(lpsznew->szline,"\0");
lpsznew=lpsznew->next;
}
else
{
lpsznew=lpsznew->next;
}
}
}
lpsznew=lpszline->next;
////问题:替换时不行,只能全删
f1.SetLength(0);
while (lpsznew)
{
strcat(lpsznew->szline,"\n");
f1.WriteString(lpsznew->szline);
lpsznew=lpsznew->next;
}
MessageBox("ok");
f1.Close();
lpsznew=lpszline;
while(lpsznew)
{
LineList * lpnext=lpsznew->next;
delete lpsznew;
lpsznew=lpnext;
}
}
void CANANDlg::OnDLfile2()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (m_Browse1=="")
{
return;
}
if (m_Browse2=="")
{
return;
}
CStdioFile f1;
CStdioFile f2;
if (!f2.Open(m_Browse1,CFile::modeReadWrite))
{
AfxMessageBox("文件没有找到或格式错误!");
return;
}
if (!f1.Open(m_Browse2,CFile::modeReadWrite))
{
AfxMessageBox("文件没有找到或格式错误!");
return;
}
char szOneline[1024] = {0};
LineList * lpszline=new LineList;
LineList * lpsznew=lpszline;
lpszline->next=NULL;
while (f1.ReadString(szOneline,1024))
{
int i=strlen(szOneline);
if (szOneline[i-1]=='\n')
{
szOneline[i-1]='\0';
}
lpsznew->next=new LineList;
lpsznew=lpsznew->next;
strcpy(lpsznew->szline,szOneline);
}
lpsznew->next=NULL;
char szOnelinef2[1024]={0};
while (f2.ReadString(szOnelinef2,1024))
{
int i=strlen(szOnelinef2);
if (szOnelinef2[i-1]=='\n')
{
szOnelinef2[i-1]='\0';
}
lpsznew=lpszline->next;
while (lpsznew)
{
if(strcmp(lpsznew->szline,szOnelinef2)==0)
{
strcpy(lpsznew->szline,"\0");
lpsznew=lpsznew->next;
}
else
{
lpsznew=lpsznew->next;
}
}
}
lpsznew=lpszline->next;
////问题:替换时不行,只能全删
f1.SetLength(0);
while (lpsznew)
{
strcat(lpsznew->szline,"\n");
f1.WriteString(lpsznew->szline);
lpsznew=lpsznew->next;
}
lpsznew=lpszline;
while(lpsznew)
{
LineList * lpnext=lpsznew->next;
delete lpsznew;
lpsznew=lpnext;
}
MessageBox("ok");
f1.Close();
}
void CANANDlg::OnDLfile3()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (m_Browse1=="")
{
return;
}
if (m_Browse2=="")
{
return;
}
CStdioFile f1;
CStdioFile f2;
if (!f1.Open(m_Browse1,CFile::modeReadWrite))
{
AfxMessageBox("文件没有找到或格式错误!");
return;
}
if (!f2.Open(m_Browse2,CFile::modeReadWrite))
{
AfxMessageBox("文件没有找到或格式错误!");
return;
}
TCHAR* pFileName = _T("e:\\anan\\3.txt");
CStdioFile fnew;
if( !fnew.Open( pFileName, CStdioFile::modeCreate | CStdioFile::modeReadWrite) )
{
#ifdef _DEBUG
afxDump << "Unable to open file" << "\n";
#endif
exit( 1 );
}
char szOneline[1024] = {0};
LineList * lpszline=new LineList;
LineList * lpsznew=lpszline;
lpszline->next=NULL;
while (f1.ReadString(szOneline,1024))
{
int i=strlen(szOneline);
if (szOneline[i-1]=='\n')
{
szOneline[i-1]='\0';
}
lpsznew->next=new LineList;
lpsznew=lpsznew->next;
strcpy(lpsznew->szline,szOneline);
}
lpsznew->next=NULL;
char szOnelinef2[1024]={0};
while (f2.ReadString(szOnelinef2,1024))
{
lpsznew=lpszline->next;
while (lpsznew)
{
int i=strlen(szOnelinef2);
if (szOnelinef2[i-1]=='\n')
{
szOnelinef2[i-1]='\0';
}
if(strcmp(lpsznew->szline,szOnelinef2)==0)
{
strcpy(lpsznew->szline,"\0");
lpsznew=lpsznew->next;
///////要删除重的
char szDlline[1024]={0};
fnew.SeekToBegin();
strcat(szOnelinef2,"\n");
if (fnew.GetLength()==0)
{
fnew.SeekToEnd();
fnew.WriteString(szOnelinef2);
}
fnew.SeekToBegin();
int nCount=0;
while (fnew.ReadString(szDlline,1024))
{
if (strcmp(szDlline,szOnelinef2)==0)
{
nCount++;
}
}
if (nCount==0)
{
fnew.SeekToEnd();
//strcat(szOnelinef2,"\n");
fnew.WriteString(szOnelinef2);
}
}
else
{
lpsznew=lpsznew->next;
}
}
}
lpsznew=lpszline->next;
////问题:替换时不行,只能全删
f1.SetLength(0);
while (lpsznew)
{
strcat(lpsznew->szline,"\n");
f1.WriteString(lpsznew->szline);
lpsznew=lpsznew->next;
}
lpsznew=lpszline;
while(lpsznew)
{
LineList * lpnext=lpsznew->next;
delete lpsznew;
lpsznew=lpnext;
}
MessageBox("ok");
f1.Close();
fnew.Close();
////////////////////////////////////////
if(!fnew.Open(pFileName,CFile::modeReadWrite))
{
return;
}
LineList * lpszline1=new LineList;
LineList * lpsznew1=lpszline1;
lpszline1->next=NULL;
f2.SeekToBegin();
while (f2.ReadString(szOneline,1024))
{
int i=strlen(szOneline);
if (szOneline[i-1]=='\n')
{
szOneline[i-1]='\0';
}
lpsznew1->next=new LineList;
lpsznew1=lpsznew1->next;
strcpy(lpsznew1->szline,szOneline);
}
lpsznew1->next=NULL;
fnew.SeekToBegin();
while (fnew.ReadString(szOnelinef2,1024))
{
int i=strlen(szOnelinef2);
if (szOnelinef2[i-1]=='\n')
{
szOnelinef2[i-1]='\0';
}
lpsznew1=lpszline1->next;
while (lpsznew1)
{
if(strcmp(lpsznew1->szline,szOnelinef2)==0)
{
strcpy(lpsznew1->szline,"\0");
lpsznew1=lpsznew1->next;
}
else
{
lpsznew1=lpsznew1->next;
}
}
}
lpsznew1=lpszline1->next;
////问题:替换时不行,只能全删
f2.SetLength(0);
while (lpsznew1)
{
strcat(lpsznew1->szline,"\n");
f2.WriteString(lpsznew1->szline);
lpsznew1=lpsznew1->next;
}
lpsznew1=lpszline1;
while(lpsznew1)
{
LineList * lpnext=lpsznew1->next;
delete lpsznew1;
lpsznew1=lpnext;
}
MessageBox("ok");
f2.Close();
fnew.Close();
}
void CANANDlg::OnChangeFile1()
{
// 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
}
void CANANDlg::OnChangeFile2()
{
// 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
}
void CANANDlg::changefile1(char * bf22,char * buffer1)
{
char * p= bf22; //一行的
char * q= buffer1;
char * s1;
char * s2;
while (*q)
{
s1=q;
s2=p;
while (*s1 && *s2 && !(*s1-*s2))
{
s1++;
s2++;
}
if (!*s2)
{
int l=strlen(p);
char * m=q;
for(int i=1;i<=l;i++)
{
*(m++)=' ';
}
}
q++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -