📄 nnbpdlg.cpp
字号:
// NNBPDlg.cpp : implementation file
//
#include "stdafx.h"
#include "NNBP.h"
#include "NNBPDlg.h"
#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 };
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CNNBPDlg dialog
CNNBPDlg::CNNBPDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNNBPDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNNBPDlg)
m_strDemoDataInput = _T("");
m_strDemoSaveNetwork = _T("");
m_strDemoSaveResult = _T("");
m_nHideLayerNumber = 0;
m_nInputLayerNumber = 0;
m_nMaxTrainTimes = LOOP_MAX_TIMES;
m_nOutputLayerNumber = 0;
m_strSimuDataInput = _T("");
m_strSimuNetworkFold = _T("");
m_strSimuResult = _T("");
m_nStep = INIT_STEP;
m_nSystemError = 0.0;
m_nSystemErrorLevel = SYSTEM_ERROR_LEVEL;
m_nTrainTimes = 0;
m_nComboArithmetic = 0;
m_nComboFunc = 2;
//}}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_STOP_TRAIN, m_btnStopTrain);
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_EXIT, m_btnExit);
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_COMBO_FUNC, m_ctrlComboFunc);
DDX_Control(pDX, IDC_COMBO_ARITHMETIC, m_ctrlComboArithmetic);
DDX_Control(pDX, IDC_BEGIN_TRAIN, m_btnBeginTrain);
DDX_Control(pDX, IDC_ABOUT_US, m_btnAboutUs);
DDX_Text(pDX, IDC_DEMO_DATA_INPUT, m_strDemoDataInput);
DDX_Text(pDX, IDC_DEMO_SAVE_NETWORK, m_strDemoSaveNetwork);
DDX_Text(pDX, IDC_DEMO_SAVE_RESULT, m_strDemoSaveResult);
DDX_Text(pDX, IDC_HIDE_LAYER_NUMBER, m_nHideLayerNumber);
DDX_Text(pDX, IDC_INPUT_LAYER_NUMBER, m_nInputLayerNumber);
DDX_Text(pDX, IDC_MAX_TRAIN_TIMES, m_nMaxTrainTimes);
DDX_Text(pDX, IDC_OUTPUT_LAYER_NUMBER, m_nOutputLayerNumber);
DDX_Text(pDX, IDC_SIMU_DATA_INPUT, m_strSimuDataInput);
DDX_Text(pDX, IDC_SIMU_NETWORK_FOLD, m_strSimuNetworkFold);
DDX_Text(pDX, IDC_SIMU_RESULT, m_strSimuResult);
DDX_Text(pDX, IDC_STEP, m_nStep);
DDX_Text(pDX, IDC_SYSTEM_ERROR, m_nSystemError);
DDX_Text(pDX, IDC_SYSTEM_LEVEL, m_nSystemErrorLevel);
DDX_Text(pDX, IDC_TRAIN_TIMES, m_nTrainTimes);
DDX_CBIndex(pDX, IDC_COMBO_FUNC, m_nComboFunc);
DDX_CBIndex(pDX, IDC_COMBO_ARITHMETIC, m_nComboArithmetic);
//}}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_ABOUT_US, OnAboutUs)
ON_BN_CLICKED(IDC_BEGIN_TRAIN, OnBeginTrain)
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_DATA_INPUT_BROWSER, OnSimuDataInputBrowser)
ON_BN_CLICKED(IDC_SIMU_NETWORK_FOLD_BROWSER, OnSimuNetworkFoldBrowser)
ON_BN_CLICKED(IDC_SIMU_RESULT_BROWSER, OnSimuResultBrowser)
ON_BN_CLICKED(IDC_STOP_TRAIN, OnStopTrain)
ON_BN_CLICKED(IDC_STATE, OnState)
ON_BN_CLICKED(IDC_EXIT, OnExit)
//}}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
/////////////////////////////////////////////////////////////////////////
// 初始化对话框上各控件的状态
//
/////////////////////////////////////////////////////////////////////
// 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_ARITHMETIC)->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()
{
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::OnAboutUs()
{
// TODO: Add your control notification handler code here
}
ULONG __stdcall WorkThreadProc(LPVOID lParam)
{
if(lParam == NULL)
return -1;
STHREADDATA *pData = (STHREADDATA *)lParam;
// Set the flag
pData->pDlg->m_bStartFlag = true;
if(pData->pDlg->m_bSimulateDataFlag)
{
pData->pDlg->SimulateData();
}
else
{
pData->pDlg->TrainingDemo();
}
pData->pDlg->m_bStartFlag = false;
delete pData;
pData = 0;
return 0;
}
void CNNBPDlg::OnBeginTrain()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
STHREADDATA* pData = new STHREADDATA;
pData->pDlg = this;
DWORD dwExitCode = 0;
::GetExitCodeThread (m_hThread, &dwExitCode);
if(dwExitCode == STILL_ACTIVE)
{
::MessageBox (this->m_hWnd, _T("程序中的训练线程仍然在运行中!"), _T("警告:"), MB_ICONWARNING | MB_OK);
return;
}
ULONG ulThreadID;
m_hThread = ::CreateThread (NULL,
0,
WorkThreadProc,
pData,
CREATE_SUSPENDED,
&ulThreadID
);
ResumeThread (m_hThread);
}
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);
::SetWindowText (hWnd, m_strDemoSaveResult);
}
else
{
return;
}
}
void CNNBPDlg::OnSimuDataInputBrowser()
{
// 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 simulate data file
CFileDialog dlg(TRUE,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -