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

📄 jiugongdlg.cpp

📁 本程序中列举了数字图象模式识别领域中的常用程序,可以在其基础上进行图象处理.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// JiugongDlg.cpp : implementation file

#include "stdafx.h"
#include "Jiugong.h"
#include "JiugongDlg.h"

#include "DialogInput.h"
#include "stdlib.h"
#include "DlgWait.h"
#include "DlgDepth.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()

/////////////////////////////////////////////////////////////////////////////
// CJiugongDlg dialog

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

void CJiugongDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CJiugongDlg)
	DDX_Control(pDX, IDC_BUTTON_SHOW, m_bshow);
	DDX_Control(pDX, IDC_BUTTON_SEARCH, m_bsearch);
	DDX_Control(pDX, IDC_BUTTON_UP, m_bup);
	DDX_Control(pDX, IDC_BUTTON_RIGHT, m_bright);
	DDX_Control(pDX, IDC_BUTTON_LEFT, m_bleft);
	DDX_Control(pDX, IDC_BUTTON_DOWN, m_bdown);
	DDX_Text(pDX, IDC_EDIT_STATE, m_stringState);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CJiugongDlg, CDialog)
	//{{AFX_MSG_MAP(CJiugongDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_DOWN, OnButtonDown)
	ON_BN_CLICKED(IDC_BUTTON_INPUT_INIT, OnButtonInputInit)
	ON_BN_CLICKED(IDC_BUTTON_INPUT_OBJ, OnButtonInputObj)
	ON_BN_CLICKED(IDC_BUTTON_LEFT, OnButtonLeft)
	ON_BN_CLICKED(IDC_BUTTON_RIGHT, OnButtonRight)
	ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
	ON_BN_CLICKED(IDC_BUTTON_SHOW, OnButtonShow)
	ON_BN_CLICKED(IDC_BUTTON_UP, OnButtonUp)
	ON_BN_CLICKED(IDC_RADIO_MAC, OnRadioMac)
	ON_BN_CLICKED(IDC_RADIO_MAN, OnRadioMan)
	ON_BN_CLICKED(IDC_BUTTON_AUTO, OnButtonAuto)
	ON_BN_CLICKED(IDC_BUTTON_DEPTH, OnButtonDepth)
	ON_BN_CLICKED(IDC_BUTTON_HUIFU, OnButtonHuifu)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CJiugongDlg message handlers

BOOL CJiugongDlg::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
	
	CenterWindow();
	// TODO: Add extra initialization here
	CWnd *pWnd0 = (CWnd *)GetDlgItem(IDC_PIC_INIT);
	pDCInit=pWnd0->GetDC();
	CWnd *pWnd1=(CWnd *)GetDlgItem(IDC_PIC_OBJ);
	pDCObj=pWnd1->GetDC();
	CWnd *pWnd2=(CWnd *)GetDlgItem(IDC_PIC_PROCESS);
	pDCCur=pWnd2->GetDC();

	m_bleft.EnableWindow(false);
	m_bup.EnableWindow(false);
	m_bright.EnableWindow(false);
	m_bdown.EnableWindow(false);
	m_bsearch.EnableWindow(false);
	m_bshow.EnableWindow(false);

	m_stringState.Format("请选择\"人工\"或\"机器\"");
	UpdateData(false);

	m_binitdown=false;
	m_bobjdown=false;
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CJiugongDlg::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 CJiugongDlg::OnPaint() 
{
	DrawJiuGong(pDCInit,m_jiugong.StateInit.state);
	DrawJiuGong(pDCObj,m_jiugong.StateObj.state);

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

void CJiugongDlg::OnButtonDown() 
{
	// TODO: Add your control notification handler code here
	Beep(1000,50);
	JGState *tempstate;
	tempstate=(JGState *)malloc(sizeof(JGState));
	if(m_nstep==0){
		m_jiugong.CopyJG(&m_jiugong.StateInit,&m_jiugong.StateCur);
		if(m_jiugong.Compare(&m_jiugong.StateCur,&m_jiugong.StateObj)==true){
			m_stringState.Format("起始状态和目标状态相同,不需移动");
			UpdateData(false);
		}
		else{
			if(m_jiugong.MoveDown(&m_jiugong.StateCur,tempstate)==true){
				m_nstep++;
				if(m_jiugong.Compare(tempstate,&m_jiugong.StateObj)==true){
					m_stringState.Format("您走了第 1 步,已经找到目标状态");
					UpdateData(false);
				}
				else{
					m_stringState.Format("您走了第 1 步,请继续走");
					UpdateData(false);
				}
				m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
			}
			else{
				m_stringState.Format("您已经不能相下移动,请重新走步");
				UpdateData(false);
			}
		}
	}
	else{
		if(m_jiugong.MoveDown(&m_jiugong.StateCur,tempstate)==true){
			m_nstep++;
			if(m_jiugong.Compare(tempstate,&m_jiugong.StateObj)==true){
				m_stringState.Format("您走了第 %d 步,已经找到目标状态",m_nstep);
				UpdateData(false);
			}
			else{
				m_stringState.Format("您走了第 %d 步,请继续走",m_nstep);
				UpdateData(false);
			}
			m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
		}
		else{
			m_stringState.Format("您已经不能相下移动,请重新走步");
			UpdateData(false);
		}
	}
	DrawJiuGong(pDCCur,(&m_jiugong.StateCur)->state);	
}

void CJiugongDlg::OnButtonInputInit() 
{
	// TODO: Add your control notification handler code here
	CDialogInput inputdlg;
	if(inputdlg.DoModal()==IDOK){
		m_jiugong.StateInit.state[0][0]=inputdlg.m_int00;
		m_jiugong.StateInit.state[0][1]=inputdlg.m_int01;
		m_jiugong.StateInit.state[0][2]=inputdlg.m_int02;
		m_jiugong.StateInit.state[1][0]=inputdlg.m_int10;
		m_jiugong.StateInit.state[1][1]=inputdlg.m_int11;
		m_jiugong.StateInit.state[1][2]=inputdlg.m_int12;
		m_jiugong.StateInit.state[2][0]=inputdlg.m_int20;
		m_jiugong.StateInit.state[2][1]=inputdlg.m_int21;
		m_jiugong.StateInit.state[2][2]=inputdlg.m_int22;
		if(CheckData(m_jiugong.StateInit.state)==false){
			MessageBox("数据不符合规范,\n请重新输入!!!","警告");
			return;
		}
		DrawJiuGong(pDCInit,m_jiugong.StateInit.state);
		DrawJiuGong(pDCCur,m_jiugong.StateInit.state);
		m_nstep=0;
		m_binitdown=true;
		if(m_binitdown==true&&m_bobjdown==true){
			m_bsearch.EnableWindow(true);
			m_bshow.EnableWindow(true);
		}
	}
}

void CJiugongDlg::OnButtonInputObj() 
{
	// TODO: Add your control notification handler code here
	CDialogInput inputdlg;
	if(inputdlg.DoModal()==IDOK){
		m_jiugong.StateObj.state[0][0]=inputdlg.m_int00;
		m_jiugong.StateObj.state[0][1]=inputdlg.m_int01;
		m_jiugong.StateObj.state[0][2]=inputdlg.m_int02;
		m_jiugong.StateObj.state[1][0]=inputdlg.m_int10;
		m_jiugong.StateObj.state[1][1]=inputdlg.m_int11;
		m_jiugong.StateObj.state[1][2]=inputdlg.m_int12;
		m_jiugong.StateObj.state[2][0]=inputdlg.m_int20;
		m_jiugong.StateObj.state[2][1]=inputdlg.m_int21;
		m_jiugong.StateObj.state[2][2]=inputdlg.m_int22;
		if(CheckData(m_jiugong.StateObj.state)==false){
			MessageBox("数据不符合规范,\n请重新输入!!!","警告");
			return;
		}
		DrawJiuGong(pDCObj,m_jiugong.StateObj.state);
		m_nstep=0;
		m_bobjdown=true;
		if(m_binitdown==true&&m_bobjdown==true){
			m_bsearch.EnableWindow(true);
			m_bshow.EnableWindow(true);
		}
	}
}

void CJiugongDlg::OnButtonLeft() 
{
	// TODO: Add your control notification handler code here
	Beep(1000,50);
	JGState *tempstate;
	tempstate=(JGState *)malloc(sizeof(JGState));
	if(m_nstep==0){
		m_jiugong.CopyJG(&m_jiugong.StateInit,&m_jiugong.StateCur);
		if(m_jiugong.Compare(&m_jiugong.StateCur,&m_jiugong.StateObj)==true){
			m_stringState.Format("起始状态和目标状态相同,不需移动");
			UpdateData(false);
		}
		else{
			if(m_jiugong.MoveLeft(&m_jiugong.StateCur,tempstate)==true){			
				m_nstep++;
				if(m_jiugong.Compare(tempstate,&m_jiugong.StateObj)==true){
					m_stringState.Format("您走了第 1 步,已经找到目标状态");
					UpdateData(false);
				}
				else{
					m_stringState.Format("您走了第 1 步,请继续走");

⌨️ 快捷键说明

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