📄 cffxdlg.cpp
字号:
// CFFXDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CFFX.h"
#include "CFFXDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CCFFXDlg dialog
CCFFXDlg::CCFFXDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCFFXDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCFFXDlg)
// 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);
}
void CCFFXDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCFFXDlg)
DDX_Control(pDX, IDC_TREE1, m_Tree);
DDX_Control(pDX, IDC_LIST1, m_List);
DDX_Control(pDX, IDC_RICHTEXTCTRL1, m_RT1);
DDX_Control(pDX, IDC_RICHTEXTCTRL2, m_RT2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCFFXDlg, CDialog)
//{{AFX_MSG_MAP(CCFFXDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(DIC_OPEN_FILE, OnOpenFile)
ON_COMMAND(IDC_FX, OnFx)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
ON_UPDATE_COMMAND_UI(IDC_FX, OnUpdateFx)
ON_COMMAND(IDC_ABOUT, OnAbout)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCFFXDlg message handlers
BOOL CCFFXDlg::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
DWORD oldStyle = m_List.GetExtendedStyle();
m_List.SetExtendedStyle(oldStyle|LVS_EX_FULLROWSELECT|LVS_EX_UNDERLINEHOT|LVS_EX_GRIDLINES);
m_List.InsertColumn(0,"索引值",LVCFMT_CENTER,70);
m_List.InsertColumn(1,"字符",LVCFMT_CENTER,143);
//////////////////////////////////////////////
TVITEM tvItem;
tvItem.mask=TVIF_TEXT;
TVINSERTSTRUCT tvInsert;
tvInsert.hInsertAfter=TVI_LAST;
tvInsert.item=tvItem;
////////////////////////////
hItemRoot=m_Tree.InsertItem("表",TVI_ROOT);
hItemkey=m_Tree.InsertItem("关键字-1",hItemRoot);
hItemborder=m_Tree.InsertItem("界限符-2",hItemRoot);
hItemarithmetic=m_Tree.InsertItem("算术符-3",hItemRoot);
hItemrelation=m_Tree.InsertItem("关系符-4",hItemRoot);
hItemconts=m_Tree.InsertItem("常量-5",hItemRoot);
hItemlabel=m_Tree.InsertItem("标识符-6",hItemRoot);
//////////////////////////////////////////////////
tvInsert.hParent=hItemkey;
for(int i=0;i<55;i++)
{
// tvItem.pszText=pAC.key[i];
m_Tree.InsertItem(pAC.key[i],hItemkey);
}
for(i=0;i<10;i++)
{
m_Tree.InsertItem(pAC.border[i],hItemborder);
}
for(i=0;i<13;i++)
{
m_Tree.InsertItem(pAC.arithmetic[i],hItemarithmetic);
}
for(i=0;i<9;i++)
{
m_Tree.InsertItem(pAC.relation[i],hItemrelation);
}
////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CCFFXDlg::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 CCFFXDlg::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 CCFFXDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCFFXDlg::OnOpenFile()
{
// TODO: Add your command handler code here
CFileDialog MyFileDlg(TRUE,NULL,NULL,0,"c源文件(*.c)|*.c|c++源文件(*.cpp)|*.cpp|所有文件(*.*)|*.*||");
if(MyFileDlg.DoModal()==IDOK)
{
pAC.strFileName=MyFileDlg.GetPathName();
CFile file;
file.Open(pAC.strFileName,CFile::modeRead);
UINT FileSize;
FileSize=file.GetLength();
CString buf;
file.Read(buf.GetBuffer(FileSize),FileSize);
file.Close();
m_RT1.SetText(buf);
}
}
void CCFFXDlg::OnFx()
{
// TODO: Add your command handler code here
pAC.FENXI();
}
void CCFFXDlg::giveresult()
{
CFile file;
file.Open("output.txt",CFile::modeRead);
UINT FileSize;
FileSize=file.GetLength();
CString buf;
file.Read(buf.GetBuffer(FileSize),FileSize);
// file.Close();
CCFFXDlg::m_RT2.SetTextRTF(buf);
}
void CCFFXDlg::showresult()
{
this->giveresult();
}
void CCFFXDlg::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
HTREEITEM hSelected;
hSelected=m_Tree.GetSelectedItem();
if(hSelected==NULL)
return;
char text[32];
TVITEM item;
item.mask=TVIF_HANDLE|TVIF_TEXT;
item.hItem=hSelected;
item.pszText=text;
item.cchTextMax=32;
m_Tree.GetItem(&item);
int i=0;
CString temp,tp;
temp.Format("%s",text);
if(temp=="关键字-1")
{
m_List.DeleteAllItems();
for(i=0;i<54;i++)
{
tp.Format("%d",i);
m_List.InsertItem(i,tp);
m_List.SetItemText(i,1,pAC.key[i]);
}
}
if(temp=="界限符-2")
{
m_List.DeleteAllItems();
for(i=0;i<11;i++)
{
tp.Format("%d",i);
m_List.InsertItem(i,tp);
m_List.SetItemText(i,1,pAC.border[i]);
}
}
if(temp=="算术符-3")
{
m_List.DeleteAllItems();
for(i=0;i<14;i++)
{
tp.Format("%d",i);
m_List.InsertItem(i,tp);
m_List.SetItemText(i,1,pAC.arithmetic[i]);
}
}
if(temp=="关系符-4")
{
m_List.DeleteAllItems();
for(int i=0;i<9;i++)
{
tp.Format("%d",i);
m_List.InsertItem(i,tp);
m_List.SetItemText(i,1,pAC.relation[i]);
}
}
if(temp=="常量-5")
{
m_List.DeleteAllItems();
for(i=0;;i++)
{
if(pAC.consts[i]==NULL)
break;
tp.Format("%d",i);
m_List.InsertItem(i,tp);
m_List.SetItemText(i,1,pAC.consts[i]);
m_Tree.InsertItem(pAC.consts[i],hItemconts);
}
}
if(temp=="标识符-6")
{
m_List.DeleteAllItems();
for(i=0;;i++)
{
if(pAC.label[i]==NULL)
break;
tp.Format("%d",i);
m_List.InsertItem(i,tp);
m_List.SetItemText(i,1,pAC.label[i]);
m_Tree.InsertItem(pAC.label[i],hItemlabel);
}
}
*pResult = 0;
}
void CCFFXDlg::OnUpdateFx(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(pAC.strFileName=="")
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable();
}
void CCFFXDlg::OnAbout()
{
// TODO: Add your command handler code here
CAboutDlg AboutDlg;
AboutDlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -