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

📄 nnbpdlg.cpp

📁 专家系统-神经网络代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// NNBPDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NNBP.h"
#include "NNBPDlg.h"


//***************************************************************************
// Add the user-defined header file
#include "AllDef.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 };
	CButtonST	m_btnHelpDocument;
	//}}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 void OnHelpdocument();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	//}}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_HELPDOCUMENT, m_btnHelpDocument);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_BN_CLICKED(IDC_HELPDOCUMENT, OnHelpdocument)
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNNBPDlg dialog

CNNBPDlg::CNNBPDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNNBPDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNNBPDlg)
	m_strDemoDataInput = _T("");
	m_strDemoSaveResult = _T("");
	m_nInputLayerNumber = 0;
	m_nHideLayerNumber = 0;
	m_nOutputLayerNumber = 0;
	m_nComboFunc = -1;
	m_nSystemError = 0.0;
	m_nTrainTimes = 0;
	m_nSystemErrorLevel = SYSTEM_ERROR_LEVEL;
	m_nMaxTrainTimes = LOOP_MAX_TIMES;
	m_strDemoSaveNetwork = _T("");
	m_strSimuNetworkFold = _T("");
	m_strSimuDataInput = _T("");
	m_strSimuResult = _T("");
	m_nComboArithmetic = -1;
	m_nStep = INIT_STEP;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	// Initialize the member variables
	m_bStartFlag = false;
	m_bSimulateDataFlag = false;


	m_SystemErrorNew	= MAX_SYSTEM_ERROR;
	m_SystemErrorOld	= MAX_SYSTEM_ERROR;

	m_hThread	=	NULL;


}

void CNNBPDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNNBPDlg)
	DDX_Control(pDX, IDC_COMBO_ARITHMETIC, m_ctrlComboArithmetic);
	DDX_Control(pDX, IDC_COMBO_FUNC, m_ctrlComboFunc);
	DDX_Control(pDX, IDC_STATIC_TITLE, m_staticTextTitle);
	DDX_Control(pDX, IDC_STATE, m_btnState);
	DDX_Control(pDX, IDC_SIMU_RESULT_BROWSER, m_btnSimuResultBrowser);
	DDX_Control(pDX, IDC_SIMU_NETWORK_FOLD_BROWSER, m_btnSimuNetworkFoldBrowser);
	DDX_Control(pDX, IDC_SIMU_DATA_INPUT_BROWSER, m_btnSimuDataInputBrowser);
	DDX_Control(pDX, IDC_DEMO_SAVE_RESULT_BROWSER, m_btnDemoSaveResultBrowser);
	DDX_Control(pDX, IDC_DEMO_SAVE_NETWORK_BROWSER, m_btnDemoSaveNetworkBrowser);
	DDX_Control(pDX, IDC_DEMO_DATA_INPUT_BROWSER, m_btnDemoDataInputBrowser);
	DDX_Control(pDX, IDC_STOP_TRAIN, m_btnStopTrain);
	DDX_Control(pDX, IDC_EXIT, m_btnExit);
	DDX_Control(pDX, IDC_ABOUT_US, m_btnAboutUs);
	DDX_Control(pDX, IDC_BEGIN_TRAIN, m_btnBeginTrain);
	DDX_Text(pDX, IDC_DEMO_DATA_INPUT, m_strDemoDataInput);
	DDX_Text(pDX, IDC_DEMO_SAVE_RESULT, m_strDemoSaveResult);
	DDX_Text(pDX, IDC_INPUT_LAYER_NUMBER, m_nInputLayerNumber);
	DDX_Text(pDX, IDC_HIDE_LAYER_NUMBER, m_nHideLayerNumber);
	DDX_Text(pDX, IDC_OUTPUT_LAYER_NUMBER, m_nOutputLayerNumber);
	DDX_CBIndex(pDX, IDC_COMBO_FUNC, m_nComboFunc);
	DDX_Text(pDX, IDC_SYSTEM_ERROR, m_nSystemError);
	DDX_Text(pDX, IDC_TRAIN_TIMES, m_nTrainTimes);
	DDX_Text(pDX, IDC_SYSTEM_LEVEL, m_nSystemErrorLevel);
	DDX_Text(pDX, IDC_MAX_TRAIN_TIMES, m_nMaxTrainTimes);
	DDX_Text(pDX, IDC_DEMO_SAVE_NETWORK, m_strDemoSaveNetwork);
	DDX_Text(pDX, IDC_SIMU_NETWORK_FOLD, m_strSimuNetworkFold);
	DDX_Text(pDX, IDC_SIMU_DATA_INPUT, m_strSimuDataInput);
	DDX_Text(pDX, IDC_SIMU_RESULT, m_strSimuResult);
	DDX_CBIndex(pDX, IDC_COMBO_ARITHMETIC, m_nComboArithmetic);
	DDX_Text(pDX, IDC_STEP, m_nStep);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNNBPDlg, CDialog)
	//{{AFX_MSG_MAP(CNNBPDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	ON_BN_CLICKED(IDC_ABOUTUS, OnAboutus)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_DEMO_DATA_INPUT_BROWSER, OnDemoDataInputBrowser)
	ON_BN_CLICKED(IDC_DEMO_SAVE_NETWORK_BROWSER, OnDemoSaveNetworkBrowser)
	ON_BN_CLICKED(IDC_DEMO_SAVE_RESULT_BROWSER, OnDemoSaveResultBrowser)
	ON_BN_CLICKED(IDC_SIMU_NETWORK_FOLD_BROWSER, OnSimuNetworkFoldBrowser)
	ON_BN_CLICKED(IDC_SIMU_DATA_INPUT_BROWSER, OnSimuDataInputBrowser)
	ON_BN_CLICKED(IDC_SIMU_RESULT_BROWSER, OnSimuResultBrowser)
	ON_BN_CLICKED(IDC_BEGIN_TRAIN, OnBeginTrain)
	ON_BN_CLICKED(IDC_STATE, OnState)
	ON_BN_CLICKED(IDC_STOP_TRAIN, OnStopTrain)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNNBPDlg message handlers

BOOL CNNBPDlg::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

	// Set the Graphic Title
	{
		m_staticTextTitle.Initialise( RGB(160,180,220) );
		m_staticTextTitle.SetAlignCentre();
		m_staticTextTitle.SetDrawShadow();
		CFont font;
		font.CreateFont(36,0,0,0,FW_BOLD,0,0,0,GB2312_CHARSET,0,0,0,0,TEXT("黑体"));
		LOGFONT logfont;
		font.GetLogFont(&logfont);
		m_staticTextTitle.SetMainTextLogFont(logfont);
	}
	
	// "浏览"按钮的资源的装入
	// For Demo Data Input Browser Button
	m_btnDemoDataInputBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
	m_btnDemoDataInputBrowser.SetIcon ( IDI_FILEOPEN);
	m_btnDemoDataInputBrowser.SetActiveBgColor (RGB(160,180,220));
	m_btnDemoDataInputBrowser.SetInactiveBgColor (RGB(160,180,220));
	m_btnDemoDataInputBrowser.AddToolTip(TEXT("浏览"));

	// For Demo Save Network Browser Button
	m_btnDemoSaveNetworkBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
	m_btnDemoSaveNetworkBrowser.SetIcon ( IDI_FILEOPEN);
	m_btnDemoSaveNetworkBrowser.SetActiveBgColor (RGB(160,180,220));
	m_btnDemoSaveNetworkBrowser.SetInactiveBgColor (RGB(160,180,220));
	m_btnDemoSaveNetworkBrowser.AddToolTip(TEXT("浏览"));

	// For Demo Save Result Browser Button
	m_btnDemoSaveResultBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
	m_btnDemoSaveResultBrowser.SetIcon ( IDI_FILEOPEN);
	m_btnDemoSaveResultBrowser.SetActiveBgColor (RGB(160,180,220));
	m_btnDemoSaveResultBrowser.SetInactiveBgColor (RGB(160,180,220));
	m_btnDemoSaveResultBrowser.AddToolTip(TEXT("浏览"));

	// For Simu Data Input Browser Button
	m_btnSimuDataInputBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
	m_btnSimuDataInputBrowser.SetIcon ( IDI_FILEOPEN);
	m_btnSimuDataInputBrowser.SetActiveBgColor (RGB(160,180,220));
	m_btnSimuDataInputBrowser.SetInactiveBgColor (RGB(160,180,220));
	m_btnSimuDataInputBrowser.AddToolTip(TEXT("浏览"));

	// For Simu Network Fold Browser Button
	m_btnSimuNetworkFoldBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
	m_btnSimuNetworkFoldBrowser.SetIcon ( IDI_FILEOPEN);
	m_btnSimuNetworkFoldBrowser.SetActiveBgColor (RGB(160,180,220));
	m_btnSimuNetworkFoldBrowser.SetInactiveBgColor (RGB(160,180,220));
	m_btnSimuNetworkFoldBrowser.AddToolTip(TEXT("浏览"));

	// For Simu Result Browser Button
	m_btnSimuResultBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
	m_btnSimuResultBrowser.SetIcon ( IDI_FILEOPEN);
	m_btnSimuResultBrowser.SetActiveBgColor (RGB(160,180,220));
	m_btnSimuResultBrowser.SetInactiveBgColor (RGB(160,180,220));
	m_btnSimuResultBrowser.AddToolTip(TEXT("浏览"));


	// "开始训练"按钮的资源的装入
	m_btnBeginTrain.SubclassDlgItem ( IDI_START,this);
	m_btnBeginTrain.SetIcon ( IDI_START);
	m_btnBeginTrain.SetActiveBgColor (RGB(160,180,220));
	m_btnBeginTrain.SetInactiveBgColor (RGB(160,180,220));
	m_btnBeginTrain.AddToolTip(TEXT("开始训练"));

	// "停止训练"按钮的资源的装入
	m_btnStopTrain.SubclassDlgItem ( IDI_STOP,this);
	m_btnStopTrain.SetIcon ( IDI_STOP);
	m_btnStopTrain.SetActiveBgColor (RGB(160,180,220));
	m_btnStopTrain.SetInactiveBgColor (RGB(160,180,220));
	m_btnStopTrain.AddToolTip(TEXT("停止训练"));

	// "显示程序状态"按钮的资源的装入
	m_btnState.SubclassDlgItem ( IDI_TRAINING,this);
	m_btnState.SubclassDlgItem ( IDI_SIMULATOR,this);
	m_btnState.SetIcon ( IDI_TRAINING);
	m_btnState.SetActiveBgColor (RGB(160,180,220));
	m_btnState.SetInactiveBgColor (RGB(160,180,220));
	m_btnState.AddToolTip (TEXT("样本训练状态"));

	// "关于我们"按钮的资源的装入
	m_btnAboutUs.SubclassDlgItem (IDI_ABOUT,this);
	m_btnAboutUs.SetIcon (IDI_ABOUT);
	m_btnAboutUs.SetActiveBgColor (RGB(160,180,220));
	m_btnAboutUs.SetInactiveBgColor (RGB(160,180,220));
	m_btnAboutUs.AddToolTip (TEXT("关于我们"));

	// "退出程序"按钮的资源的装入--->Yes
	m_btnExit.SubclassDlgItem (IDI_EXIT,this);
	m_btnExit.SetIcon (IDI_EXIT);
	m_btnExit.SetActiveBgColor (RGB(160,180,220));
	m_btnExit.SetInactiveBgColor (RGB(160,180,220));
	m_btnExit.AddToolTip (TEXT("退出程序"));

	/////////////////////////////////////////////////////////////////////////
	// 初始化对话框上各控件的状态
	//

	/////////////////////////////////////////////////////////////////////
	// Disabled the following controls
	/////////////////////////////////////////////////////////////////////
	(CNNBPDlg *)GetDlgItem(IDC_SIMU_NETWORK_FOLD)->EnableWindow(FALSE);

	(CNNBPDlg *)GetDlgItem(IDC_SIMU_NETWORK_FOLD_BROWSER)->EnableWindow(FALSE);

	(CNNBPDlg *)GetDlgItem(IDC_SIMU_DATA_INPUT)->EnableWindow(FALSE);

	(CNNBPDlg *)GetDlgItem(IDC_SIMU_DATA_INPUT_BROWSER)->EnableWindow(FALSE);

	(CNNBPDlg *)GetDlgItem(IDC_SIMU_RESULT)->EnableWindow(FALSE);

	(CNNBPDlg *)GetDlgItem(IDC_SIMU_RESULT_BROWSER)->EnableWindow(FALSE);

	/////////////////////////////////////////////////////////////////////
	// Enabled the following controls
	/////////////////////////////////////////////////////////////////////
	(CNNBPDlg *)GetDlgItem(IDC_SYSTEM_LEVEL)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_MAX_TRAIN_TIMES)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_STEP)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_INPUT_LAYER_NUMBER)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_HIDE_LAYER_NUMBER)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_OUTPUT_LAYER_NUMBER)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_COMBO_TRAIN)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_COMBO_FUNC)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_DEMO_DATA_INPUT)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_DEMO_DATA_INPUT_BROWSER)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_NETWORK)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_NETWORK_BROWSER)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_RESULT)->EnableWindow(TRUE);

	(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_RESULT_BROWSER)->EnableWindow(TRUE);	

	//
	// End of initializing the state of the controls on the CNNBPDlg
	/////////////////////////////////////////////////////////////////////////


	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CNNBPDlg::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 CNNBPDlg::OnPaint() 
{
	// Draw the title label
	m_staticTextTitle.SetMainTextColour (RGB(0,128,192));
	m_staticTextTitle.Display (TEXT("神经网络仿真工具"),TEXT(""),0);

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

void CNNBPDlg::OnExit() 
{
	// TODO: Add your control notification handler code here
	DWORD dwExitCode = 0;

	if(::GetExitCodeThread (m_hThread, &dwExitCode))
	{
		if(dwExitCode == STILL_ACTIVE)
		{
			::TerminateThread (m_hThread, (DWORD)0);
		}

		CloseHandle (m_hThread);
		m_hThread = NULL;
	}

	CDialog::OnOK ();
	
}

void CNNBPDlg::OnAboutus() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg	dlg;
	if(dlg.DoModal () == IDOK)
		return;
	
}

void CNNBPDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnTimer(nIDEvent);
}

void CNNBPDlg::OnDemoDataInputBrowser() 
{
	// TODO: Add your control notification handler code here
	static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
	static char BASED_CODE lpszDefExt[] = TEXT("txt");

	//Create the dialog to select the demo data file to load the data
	CFileDialog dlg(TRUE,
		            lpszDefExt,
					NULL,
					OFN_READONLY		| 
					OFN_FILEMUSTEXIST   |
					OFN_PATHMUSTEXIST,
					szFilter,
					this);

	if(dlg.DoModal () == IDOK)
	{
		m_strDemoDataInput = dlg.GetPathName ();
		
		HWND hWnd = ::GetDlgItem (this->m_hWnd,IDC_DEMO_DATA_INPUT);
		::SetWindowText (hWnd,m_strDemoDataInput);

	}
	else
	{
		return;
	}
	
}

void CNNBPDlg::OnDemoSaveNetworkBrowser() 
{
	// TODO: Add your control notification handler code here

	static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
	static char BASED_CODE lpszDefExt[] = TEXT("txt");

	//Create the dialog to select the demo data file to save the network
	CFileDialog dlg(FALSE,
		            lpszDefExt,
					NULL,
					OFN_HIDEREADONLY    | 
					OFN_CREATEPROMPT	|
					OFN_OVERWRITEPROMPT,
					szFilter,
					this );

	if(dlg.DoModal ()==IDOK)
	{
		m_strDemoSaveNetwork = dlg.GetPathName ();

		HWND hWnd = ::GetDlgItem (this->m_hWnd,IDC_DEMO_SAVE_NETWORK);
		::SetWindowText (hWnd,m_strDemoSaveNetwork);

	}
	else
	{
		return;
	}

}

void CNNBPDlg::OnDemoSaveResultBrowser() 
{
	// TODO: Add your control notification handler code here

	static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
	static char BASED_CODE lpszDefExt[] = TEXT("txt");

	//Create the dialog to select the demo data file to save the result
	CFileDialog dlg(FALSE,
		            lpszDefExt,
					NULL,
					OFN_HIDEREADONLY    | 
					OFN_CREATEPROMPT	|
					OFN_OVERWRITEPROMPT,
					szFilter,
					this);

	if(dlg.DoModal ()==IDOK)
	{
		m_strDemoSaveResult = dlg.GetPathName ();
		
		HWND hWnd = ::GetDlgItem (this->m_hWnd , IDC_DEMO_SAVE_RESULT);

⌨️ 快捷键说明

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