?? 數字識別dlg.cpp
字號:
// 數字識別Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "數字識別.h"
#include "數字識別Dlg.h"
#include <fstream.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()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
m_res = -1;
m_0 = FALSE;
m_1 = FALSE;
m_2 = FALSE;
m_3 = FALSE;
m_4 = FALSE;
m_5 = FALSE;
m_6 = FALSE;
m_7 = FALSE;
m_8 = FALSE;
m_9 = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
init = TRUE;
lbd = FALSE;
show = data.GetData();
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Text(pDX, IDC_RES, m_res);
DDX_Check(pDX, IDC_C0, m_0);
DDX_Check(pDX, IDC_C1, m_1);
DDX_Check(pDX, IDC_C2, m_2);
DDX_Check(pDX, IDC_C3, m_3);
DDX_Check(pDX, IDC_C4, m_4);
DDX_Check(pDX, IDC_C5, m_5);
DDX_Check(pDX, IDC_C6, m_6);
DDX_Check(pDX, IDC_C7, m_7);
DDX_Check(pDX, IDC_C8, m_8);
DDX_Check(pDX, IDC_C9, m_9);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
ON_BN_CLICKED(IDC_BUTTON_SHOW, OnButtonShow)
ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
ON_BN_CLICKED(IDC_BUTTON_STUDY, OnButtonStudy)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::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 CMyDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{
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();
}
dc.MoveTo(9,9);
dc.LineTo(110,9);
dc.LineTo(110,150);
dc.LineTo(9,150);
dc.LineTo(9,9);
dc.MoveTo(129,9);
dc.LineTo(230,9);
dc.LineTo(230,150);
dc.LineTo(129,150);
dc.LineTo(129,9);
if(init){
CDC * pdc = new CDC();
pdc->CreateCompatibleDC(&dc);
CBitmap * obp;
CBitmap * bmp = new CBitmap();
bmp->LoadBitmap(IDB_BG);
obp = pdc->SelectObject(bmp);
init = FALSE;
dc.BitBlt(10,10,100,140,pdc,0,0,SRCCOPY);
pdc->SelectObject(obp);
delete bmp;
delete pdc;
}
else{
if(NULL == data.GetDc()){
CDC * pdc = new CDC();
pdc->CreateCompatibleDC(&dc);
CBitmap * bmp = new CBitmap();
bmp->LoadBitmap(IDB_BG);
pdc->SelectObject(bmp);
data.SetDc(pdc);
}
dc.BitBlt(10,10,100,140,data.GetDc(),0,0,SRCCOPY);
}
CDC * tdc = new CDC();
tdc->CreateCompatibleDC(&dc);
CBitmap * tbmp = new CBitmap();
CBitmap * obmp;
tbmp->LoadBitmap(IDB_BG);
obmp = tdc->SelectObject(tbmp);
CDC * tdcd = new CDC();
tdcd->CreateCompatibleDC(&dc);
CBitmap * tbmpc = new CBitmap();
tbmpc->LoadBitmap(IDB_B);
CBitmap * obmpc;
obmpc = tdcd->SelectObject(tbmpc);
for(int i = 0;i < 10; i++){
for(int j = 0;j < 14; j++){
if(1 == show[i*14 + j]){
// if('1' == data.GetData(i,j)){
tdc->BitBlt(i*10,j*10,10,10,tdcd,0,0,SRCCOPY);
}
}
}
dc.BitBlt(130,10,100,140,tdc,0,0,SRCCOPY);
tdc->SelectObject(obmp);
tdcd->SelectObject(obmpc);
delete tdc;
delete tdcd;
delete tbmp;
delete tbmpc;
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(point.x > 9 && point.x < 110 && point.y > 9 && point.y < 150){
lbd = TRUE;
data.MoveTo(point.x - 10,point.y - 10);
}
CDialog::OnLButtonDown(nFlags, point);
}
void CMyDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(lbd){
data.LineTo(point.x - 10, point.y - 10);
}
Invalidate(FALSE);
lbd = FALSE;
CDialog::OnLButtonUp(nFlags, point);
}
void CMyDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(lbd){
data.LineTo(point.x - 10, point.y - 10);
}
Invalidate(FALSE);
CDialog::OnMouseMove(nFlags, point);
}
void CMyDlg::OnButtonClear()
{
// TODO: Add your control notification handler code here
data.Clear();
Invalidate(FALSE);
// CString str;
// char tc[] = "te";
// char * tempStr = new char[strlen(tc)+5];
// strcpy(tempStr,"data/");
// MessageBox(str);
}
void CMyDlg::OnButtonShow()
{
// TODO: Add your control notification handler code here
data.Show();
show = data.GetData();
Invalidate(FALSE);
m_res = rec.Get(data.GetData());
UpdateData(FALSE);
}
void CMyDlg::OnButtonSave()
{
// TODO: Add your control notification handler code here
rec.Save();
}
void CMyDlg::OnButtonStudy()
{
// TODO: Add your control notification handler code here
int tr;
int j = 0;
int nr = 0;
do{
nr = 0;
ifstream inf("data/yb.txt");
int tint[10];
int tres = -99;
inf>>tres;
while(tres > -99){
inf>>tint[0];
inf>>tint[1];
inf>>tint[2];
inf>>tint[3];
inf>>tint[4];
inf>>tint[5];
inf>>tint[6];
inf>>tint[7];
inf>>tint[8];
inf>>tint[9];
int tipt[140];
for(int i = 0;i < 140; i++){
inf>>tipt[i];
}
rec.Study(tipt, tint);
tr = rec.Get(tipt);
if(tr != tres){
nr++;
}
tres = -99;
inf>>tres;
}
inf.close();
j ++;
CString str;
str.Format("學習了%d次", j);
SetDlgItemText(IDC_INFO, str);
}
while(nr > 0 && j < 1000);
}
void CMyDlg::OnButtonAdd()
{
// TODO: Add your control notification handler code here
UpdateData();
ofstream ofs("data/yb.txt", ios::app);
ofs<<m_res<<" ";
if(m_0){ofs<<"1 ";}else{ofs<<"0 ";}
if(m_1){ofs<<"1 ";}else{ofs<<"0 ";}
if(m_2){ofs<<"1 ";}else{ofs<<"0 ";}
if(m_3){ofs<<"1 ";}else{ofs<<"0 ";}
if(m_4){ofs<<"1 ";}else{ofs<<"0 ";}
if(m_5){ofs<<"1 ";}else{ofs<<"0 ";}
if(m_6){ofs<<"1 ";}else{ofs<<"0 ";}
if(m_7){ofs<<"1 ";}else{ofs<<"0 ";}
if(m_8){ofs<<"1 ";}else{ofs<<"0 ";}
if(m_9){ofs<<"1 ";}else{ofs<<"0 ";}
for(int i = 0;i < 140; i++){
ofs<<show[i]<<" ";
}
ofs<<endl;
ofs.close();
// CString str;
// str.Format("樣本總數:%d", );
// SetDlgItemText(IDC_INFO, str);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -