📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include <conio.h>
#include <process.h>
#include <string.h>
#include "stdafx.h"
#include "AdaBoost.h"
#include "TrainDlg.h"
#include "MainFrm.h"
#include "Adaboost_train_main.h"
#include "Adaboost_common.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
ON_COMMAND(ID_FILE_TRAIN, OnFileTrain)
ON_MESSAGE(WM_COMPUTATION_FINISH,OnComputationFinish)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME,OnUpdateTime)
ON_MESSAGE(WM_COMPUTATION_FINISH,OnComputationFinish)
ON_WM_TIMER()
ON_COMMAND(ID_CLEAR_TEXT, OnClearText)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_TIME,
//ID_INDICATOR_NUM,
//ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndStatusBar.SetPaneInfo(1,ID_INDICATOR_TIME,SBPS_NORMAL,150);
m_nTimeIndex=m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIME);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
UINT ComputeThreadProc(LPVOID pParam)
{
// char errorTrainfile[200];
// char errorTestfile[200];
Adaboost_train_main();
if (com_pro.show_openfile)
{
char* cmdline;
char oldline[200]="notepad ";
cmdline=strcat(oldline, com_param.resultfile);
WinExec(cmdline,3);
}
::PostMessage((HWND)pParam,WM_COMPUTATION_FINISH,0,0);
return 0;
}
void CMainFrame::OnFileTrain()
{
CLearnDlg Ld;
Ld.m_strTrain=com_param.trainfile;
Ld.m_strTest=com_param.trainfile;
Ld.m_strResult=com_param.resultfile;
if (Ld.DoModal()==IDOK)
{
com_pro.show_openfile=Ld.m_bOpen;
strcpy(com_param.trainfile,Ld.m_strTrain);
strcpy(com_param.testfile,Ld.m_strTest);
strcpy(com_param.resultfile,Ld.m_strResult);
GetActiveView()->SetWindowText(NULL);
BeginComputation();
CWinThread* pThread=
AfxBeginThread(ComputeThreadProc,GetSafeHwnd(),THREAD_PRIORITY_NORMAL);
}
}
void CMainFrame::BeginComputation()
{
com_param.Running=TRUE;
com_param.Finished=FALSE;
temp_pro.Copy(com_pro);
m_nTimer=SetTimer(1001,500,NULL);
m_tmBegin=CTime::GetCurrentTime();
}
void CMainFrame::OnComputationFinish(WPARAM wParam,LPARAM lParam)
{
CeaseComputation();
}
void CMainFrame::CeaseComputation()
{
if (com_param.Running==FALSE)
printm("----Computation was stop by user.");
com_param.Running=FALSE;
com_param.Finished=TRUE;
com_pro.Copy(temp_pro);
KillTimer(m_nTimer);
m_wndStatusBar.SetPaneText(1,"Waiting...");
if (com_param.Close)
CFrameWnd::OnClose();
}
void CMainFrame::OnUpdateTime(CCmdUI* pCmdUI)
{
pCmdUI->Enable();
pCmdUI->SetText(m_strTime);
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
CTimeSpan t=CTime::GetCurrentTime()-m_tmBegin;
m_strTime=t.Format("Computing %H:%M:%S already");
m_wndStatusBar.SetPaneText(1,m_strTime,TRUE);
CFrameWnd::OnTimer(nIDEvent);
}
void CMainFrame::OnClearText()
{
GetActiveView()->SetWindowText(NULL);
}
void CMainFrame::OnClose()
{
if (!com_param.Finished)
{
if( AfxMessageBox("Still computing ,Do you want to exit?",MB_YESNO)==IDYES)
{
com_param.Running=FALSE;
com_param.Close=TRUE;
return ;
}
else return ;
}
else CFrameWnd::OnClose();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -