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

📄 testdlg.cpp

📁 一个面向对象的产生式推理模型
💻 CPP
字号:
// testDlg.cpp : implementation file
//

#include "stdafx.h"
#include "test.h"
#include "testDlg.h"
#include "editdlg.h"
#include "hyperlink.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CHyperLink	m_MailTo;
	//}}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)
	virtual BOOL OnInitDialog();
	//}}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)
	DDX_Control(pDX, IDC_STATIC_MAIL, m_MailTo);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
 
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog

CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestDlg)
	m_Answer = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	filename = "";
}

void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestDlg)
	DDX_Control(pDX, IDC_BUTTON1, m_AboutText);
	DDX_Control(pDX, IDC_TREE1, m_tree1);
	DDX_Text(pDX, IDC_ANSWER, m_Answer);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
	//{{AFX_MSG_MAP(CTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_NEW_FILE, OnNewFile)
	ON_BN_CLICKED(IDC_OPEN_FILE, OnOpenFile)
	ON_BN_CLICKED(ID_EDIT_CONTENT, OnEditContent)
	ON_BN_CLICKED(IDC_BEGIN_SEARCH, OnBeginSearch)
	ON_BN_CLICKED(IDC_TEST_FOR_J, OnTestForJ)
	ON_BN_CLICKED(IDC_SELF_CHECK, OnSelfCheck)
	ON_BN_CLICKED(IDC_BUTTON_SAVE_AS, OnButtonSaveAs)
	ON_BN_CLICKED(IDC_FILE_RESET, OnFileReset)
	ON_BN_CLICKED(IDC_SHOW_SEARCH_TREE, OnShowSearchTree)
	ON_WM_LBUTTONDOWN()
	ON_WM_CREATE()
	ON_WM_KILLFOCUS()
	ON_BN_CLICKED(IDC_BUTTON1, OnMessionButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers

BOOL CTestDlg::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
	HICON hIcon = AfxGetApp() ->LoadIcon(IDI_ICON);
	ASSERT(hIcon);
	AfxGetMainWnd() ->SendMessage(WM_SETICON,TRUE,(LPARAM)hIcon);
	if (filename == "" ){
		filename = AfxGetApp()->GetProfileString("Settings",
			"last es file");
	}
	CFile f;
	CString title;
	
	if (f.Open(filename,CFile::modeRead))
	{
		CArchive ar(&f,CArchive::load);
		ar>>title;
		GetDlgItem(IDC_BEGIN_SEARCH)->EnableWindow(true);
		GetDlgItem(ID_EDIT_CONTENT)->EnableWindow(true);
		GetDlgItem(IDC_SELF_CHECK)->EnableWindow(true);
		GetDlgItem(IDC_TEST_FOR_J)->EnableWindow(true);
		GetDlgItem(IDC_BUTTON_SAVE_AS)->EnableWindow(true);
		GetDlgItem(IDC_FILE_RESET)->EnableWindow(true);
		ar.Close();
		f.Close();
		myExpert.LoadFromFile(filename);
	}
	if (!title.IsEmpty())
		SetWindowText(title);
	TestExpert();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestDlg::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 CTestDlg::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 CTestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTestDlg::TestExpert()
{/*
	CString str = "asdf";
	char temp[20];
	strcpy(temp,str);
	str = temp;
	char* t;
	t = ( char *)str;*/
	//myExpert.SingleSearchForSelfCheck();

}

void CTestDlg::OnOK() 
{
	CDialog::OnOK();
}

void CTestDlg::OnNewFile() 
{
	// TODO: Add your control notification handler code here
	static char BASED_CODE szFilterMIDI[]="Expert System Files(*.es)|*.es||";
	CFileDialog fileopenbox(false,"专家系统文件",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilterMIDI);
	fileopenbox.m_ofn.lpstrTitle="新建ES文件";
	if(fileopenbox.DoModal()!=IDOK){
		return;
	}
	CString tempName;
	tempName = fileopenbox.GetPathName();
//
	CFile f;
	if (f.Open(tempName,CFile::modeWrite | CFile::modeCreate)){
		GetDlgItem(IDC_BEGIN_SEARCH)->EnableWindow(true);
		GetDlgItem(IDC_BUTTON_SAVE_AS)->EnableWindow(true);
		GetDlgItem(IDC_FILE_RESET)->EnableWindow(true);
		f.Close();
		filename = tempName;
	}
	else {
		GetDlgItem(IDC_BEGIN_SEARCH)->EnableWindow(false);
		GetDlgItem(IDC_BUTTON_SAVE_AS)->EnableWindow(false);
		GetDlgItem(IDC_FILE_RESET)->EnableWindow(false);
		return;
	}
//
	myExpert.InitData();
	AiAssert A("长翅膀","不长翅膀");
	AiAssert B("翅膀有力","翅膀没力");
	AiAssert C("会飞","不会飞");
	myExpert.AddRule(B&A,C);
	myExpert.AddRule(!A,!C);
	myExpert.AddRule(!B,!C);
	myExpert.AddGoal(C);
	myExpert.SetESName("XXXX专家系统");
	myExpert.StoreToFile(filename);
	SetWindowText("XXXX专家系统");
	m_Answer = myExpert.GetGoalString();
		GetDlgItem(IDC_BEGIN_SEARCH)->EnableWindow(true);
		GetDlgItem(ID_EDIT_CONTENT)->EnableWindow(true);
		GetDlgItem(IDC_SELF_CHECK)->EnableWindow(true);
		GetDlgItem(IDC_TEST_FOR_J)->EnableWindow(true);
		GetDlgItem(IDC_BUTTON_SAVE_AS)->EnableWindow(true);
		GetDlgItem(IDC_FILE_RESET)->EnableWindow(true);
	UpdateData(false);
}

void CTestDlg::OnOpenFile() 
{
	// TODO: Add your control notification handler code here
	static char BASED_CODE szFilterMIDI[]="Expert System Files(*.es)|*.es||";
	CFileDialog fileopenbox(TRUE,"专家系统文件",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilterMIDI);
	fileopenbox.m_ofn.lpstrTitle="打开ES文件";
	if(fileopenbox.DoModal()!=IDOK){
		return;
	}
	CString tempName = fileopenbox.GetPathName();
	CFile f;
	if (f.Open(tempName,CFile::modeRead))
	{
		CArchive ar(&f,CArchive::load);
		ar.Close();
		f.Close();
		filename = tempName;
		myExpert.LoadFromFile(filename);
		GetDlgItem(IDC_BEGIN_SEARCH)->EnableWindow(true);
		GetDlgItem(ID_EDIT_CONTENT)->EnableWindow(true);
		GetDlgItem(IDC_SELF_CHECK)->EnableWindow(true);
		GetDlgItem(IDC_TEST_FOR_J)->EnableWindow(true);
		GetDlgItem(IDC_BUTTON_SAVE_AS)->EnableWindow(true);
		GetDlgItem(IDC_FILE_RESET)->EnableWindow(true);
	}
	else{
		GetDlgItem(IDC_BEGIN_SEARCH)->EnableWindow(false);
		GetDlgItem(IDC_BUTTON_SAVE_AS)->EnableWindow(false);
		GetDlgItem(IDC_FILE_RESET)->EnableWindow(false);
	}
	CString title = myExpert.GetESName();
	if (!title.IsEmpty())
		SetWindowText(title);
	else 
		SetWindowText("专家系统模型测试工具");
}

void CTestDlg::OnEditContent() 
{
	// TODO: Add your control notification handler code here
	m_pEditDlg = new EditDlg;
	m_pEditDlg->filename = filename;
	m_pEditDlg->myExpert = &myExpert;
	m_pEditDlg->Create();
}

void CTestDlg::OnBeginSearch() 
{
	// TODO: Add your control notification handler code here
	CFile f;
	if (f.Open(filename,CFile::modeRead))
		f.Close();	
	else 
		return;
	myExpert.LoadFromFile(filename);
	m_Answer = myExpert.GetGoalString();
	UpdateData(false);
	myExpert.Search();
	m_Answer = myExpert.GetAnswerString();
	if (m_Answer.IsEmpty())
		m_Answer = "无法推出目标命题";
	UpdateData(FALSE);
	//
	CImageList *pImageList;
	pImageList=new CImageList();
	pImageList->Create(15, 15, TRUE, 6, 4);
	CBitmap bitmap;
	for(int nID=IDB_BITMAP1;nID<=IDB_BITMAP6;nID++)
	{
	 bitmap.LoadBitmap(nID);
	 pImageList->Add(&bitmap,(COLORREF)0xFFFFFF);
	 bitmap.DeleteObject();
	}
	m_tree1.SetImageList(pImageList,TVSIL_NORMAL);

	myExpert.SetAnswerTreeCtrl(&m_tree1);
	m_tree1.DeleteAllItems();
	//
	myExpert.ShowTreeCtrlAnswer();
}

void CTestDlg::PostNcDestroy() 
{
	// TODO: Add your specialized code here and/or call the base class
	AfxGetApp()->WriteProfileString("Settings",
			"last es file",filename);
	CDialog::PostNcDestroy();
}

void CTestDlg::OnTestForJ() 
{
	TestJDlg testForJDlg;
	testForJDlg.filename = filename;
	testForJDlg.DoModal();
}

void CTestDlg::OnSelfCheck() 
{
	myExpert.LoadFromFile(filename);
	//myExpert.SelfCheck();
	myExpert.SelfCheckLikeAsk();
}

void CTestDlg::OnButtonSaveAs() 
{
	static char BASED_CODE szFilterMIDI[]="Expert System Files(*.es)|*.es||";
	CFileDialog fileopenbox(false,"专家系统文件",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilterMIDI);
	fileopenbox.m_ofn.lpstrTitle="另存为ES文件";
	if(fileopenbox.DoModal()!=IDOK){
		return;
	}
	CString tempName;
	tempName = fileopenbox.GetPathName();
	CFile f;
	if (f.Open(tempName,CFile::modeWrite | CFile::modeCreate)){
		GetDlgItem(IDC_BEGIN_SEARCH)->EnableWindow(true);
		GetDlgItem(IDC_BUTTON_SAVE_AS)->EnableWindow(true);
		GetDlgItem(IDC_FILE_RESET)->EnableWindow(true);
		f.Close();
		filename = tempName;
	}
	else {
		GetDlgItem(IDC_BEGIN_SEARCH)->EnableWindow(false);
		GetDlgItem(IDC_BUTTON_SAVE_AS)->EnableWindow(false);
		GetDlgItem(IDC_FILE_RESET)->EnableWindow(false);
		return;
	}
	myExpert.StoreToFile(filename);
	CString title;
	title = myExpert.GetESName();
	if (!title.IsEmpty())
		SetWindowText(title);
	else 
		SetWindowText("专家系统模型测试工具");
	SetWindowText(title);
	m_Answer = myExpert.GetGoalString();
	GetDlgItem(IDC_BEGIN_SEARCH)->EnableWindow(true);
	GetDlgItem(ID_EDIT_CONTENT)->EnableWindow(true);
	GetDlgItem(IDC_SELF_CHECK)->EnableWindow(true);
	GetDlgItem(IDC_TEST_FOR_J)->EnableWindow(true);
	GetDlgItem(IDC_BUTTON_SAVE_AS)->EnableWindow(true);
	GetDlgItem(IDC_FILE_RESET)->EnableWindow(true);
	UpdateData(false);	
}

void CTestDlg::OnFileReset() 
{
	myExpert.LoadFromFile(filename);	
}

void CTestDlg::OnShowSearchTree() 
{
	// TODO: Add your control notification handler code here
	CImageList *pImageList;
	pImageList=new CImageList();
	pImageList->Create(15, 15, TRUE, 6, 4);
	CBitmap bitmap;
	for(int nID=IDB_BITMAP1;nID<=IDB_BITMAP6;nID++)
	{
	 bitmap.LoadBitmap(nID);
	 pImageList->Add(&bitmap,(COLORREF)0xFFFFFF);
	 bitmap.DeleteObject();
	}
	m_tree1.SetImageList(pImageList,TVSIL_NORMAL);

	myExpert.SetAnswerTreeCtrl(&m_tree1);

	myExpert.ShowTreeCtrlAnswer();
}

void CTestDlg::OnMessionButton() 
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_MailTo.SetURL(_T("mailto:why@nanjing-fnst.com"));
	m_MailTo.SetUnderline(FALSE);
//	m_HyperLink.SetLinkCursor(AfxGetApp()->LoadCursor(IDC_HAND));
	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 + -