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

📄 simplecaidlg.cpp

📁 我要下载源代码我要源代码我要下载代码我要下载源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SimpleCAIDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SimpleCAI.h"
#include "SimpleCAIDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CSimpleCAIDlg dialog

CSimpleCAIDlg::CSimpleCAIDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSimpleCAIDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSimpleCAIDlg)
	m_strEditCode = _T("");
	m_strAddrA = _T("");
	m_strAddrB = _T("");
	m_strA = _T("");
	m_strB = _T("");
	m_strX = _T("");
	m_strY = _T("");
	m_strTemp = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_nCodeLine = 0;
	m_nStarCharIndex = 0;
	m_nEndCharIndex = 0;
	m_nStatus = 0;

}

void CSimpleCAIDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSimpleCAIDlg)
	DDX_Control(pDX, IDC_EDIT_TEMP, m_edtTemp);
	DDX_Control(pDX, IDC_EDIT_Y, m_edtY);
	DDX_Control(pDX, IDC_EDIT_X, m_edtX);
	DDX_Control(pDX, IDC_EDIT_B, m_edtB);
	DDX_Control(pDX, IDC_EDIT_A, m_edtA);
	DDX_Control(pDX, IDC_STATIC_ADDR_B, m_stcAddrB);
	DDX_Control(pDX, IDC_STATIC_ADDR_A, m_stcAddrA);
	DDX_Control(pDX, IDC_BUTTON_CODE2, m_btnCode2);
	DDX_Control(pDX, IDC_BUTTON_CODE1, m_btnCode1);
	DDX_Control(pDX, IDC_BUTTON_STOP, m_btnStop);
	DDX_Control(pDX, IDC_BUTTON_STEP, m_btnStep);
	DDX_Control(pDX, IDC_STATIC_LABLE_Y, m_stcLableY);
	DDX_Control(pDX, IDC_STATIC_LABLE_X, m_stcLableX);
	DDX_Control(pDX, IDC_STATIC_LABLE_TEMP, m_stcLableTemp);
	DDX_Control(pDX, IDC_STATIC_LABLE_B, m_stcLableB);
	DDX_Control(pDX, IDC_STATIC_LABLE_A, m_stcLableA);
	DDX_Control(pDX, IDC_EDIT_CODE, m_edtCode);
	DDX_Text(pDX, IDC_EDIT_CODE, m_strEditCode);
	DDX_Text(pDX, IDC_STATIC_ADDR_A, m_strAddrA);
	DDX_Text(pDX, IDC_STATIC_ADDR_B, m_strAddrB);
	DDX_Text(pDX, IDC_EDIT_A, m_strA);
	DDX_Text(pDX, IDC_EDIT_B, m_strB);
	DDX_Text(pDX, IDC_EDIT_X, m_strX);
	DDX_Text(pDX, IDC_EDIT_Y, m_strY);
	DDX_Text(pDX, IDC_EDIT_TEMP, m_strTemp);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSimpleCAIDlg, CDialog)
	//{{AFX_MSG_MAP(CSimpleCAIDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_CODE1, OnButtonCode1)
	ON_BN_CLICKED(IDC_BUTTON_CODE2, OnButtonCode2)
	ON_BN_CLICKED(IDC_BUTTON_STEP, OnButtonStep)
	ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
	ON_WM_SIZE()
	ON_WM_MOVE()
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSimpleCAIDlg message handlers

BOOL CSimpleCAIDlg::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
	m_btnStep.EnableWindow(false);
	m_btnStop.EnableWindow(false);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSimpleCAIDlg::SetCode(int codeNumber)
{
	m_strEditCode.Empty();
	m_strMain.Empty();
	m_strSwap.Empty();

	if(codeNumber == 1)
	{
		m_strMain =  "void swap(int x, int y);\r\n";
		m_strMain += "main()\r\n";
		m_strMain += "{\r\n";
		m_strMain += "    int a, b;\r\n";
		m_strMain += "    a = 10;\r\n";
		m_strMain += "    b = 20;\r\n";
		m_strMain += "    swap(a, b);\r\n";
		m_strMain += "    printf(\"a=%d, b=%d\",a, b);\r\n";
		m_strMain += "}\r\n";

		m_strSwap +=  "void swap(int x, int y)\r\n";
		m_strSwap += "{\r\n";
		m_strSwap += "    int temp;\r\n";
		m_strSwap += "    temp = x;\r\n";
		m_strSwap += "    x = y;\r\n";
		m_strSwap += "    y = temp;\r\n";
		m_strSwap += "}\r\n";
	}
	else
	{
		m_strMain =  "void swap(int *x, int *y);\r\n";
		m_strMain += "main()\r\n";
		m_strMain += "{\r\n";
		m_strMain += "    int a, b;\r\n";
		m_strMain += "    a = 10;\r\n";
		m_strMain += "    b = 20;\r\n";
		m_strMain += "    swap(&a, &b);\r\n";
		m_strMain += "    printf(\"a=%d, b=%d\",a, b);\r\n";
		m_strMain += "}\r\n";

		m_strSwap +=  "void swap(int *x, int *y)\r\n";
		m_strSwap += "{\r\n";
		m_strSwap += "    int temp;\r\n";
		m_strSwap += "    temp = *x;\r\n";
		m_strSwap += "    *x = *y;\r\n";
		m_strSwap += "    *y = temp;\r\n";
		m_strSwap += "}\r\n";
	}

	m_strEditCode = m_strMain;
	m_strEditCode += "\r\n";
	m_strEditCode += m_strSwap;

	m_strRemainCode = m_strEditCode;

	m_btnStep.EnableWindow(true);
	UpdateData(false);
}

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

void CSimpleCAIDlg::OnButtonCode1() 
{
	// TODO: Add your control notification handler code here
	m_nCodeNumber = 1;
	SetCode(1);
	
}

void CSimpleCAIDlg::OnButtonCode2() 
{
	// TODO: Add your control notification handler code here
	m_nCodeNumber = 2;
	SetCode(2);
	
}

void CSimpleCAIDlg::MoveAXBY(CClientDC *pDC,int codeNumber)
{
	CRect rctA, rctB, rctX, rctY;
	int i;
	m_edtA.GetWindowRect(&rctA);
	m_edtB.GetWindowRect(&rctB);
	m_edtX.GetWindowRect(&rctX);
	m_edtY.GetWindowRect(&rctY);
	CString strA, strB;
	if(codeNumber == 1)
	{
		strA = m_strA;
		strB = m_strB;
	}
	else
	{
		strA = m_strAddrA;
		strB = m_strAddrB;
	}

	for(i=rctA.bottom - m_rctWindow.top; i<rctX.top - m_rctWindow.top - 20; i++)
	{
		pDC->TextOut(rctA.left - m_rctWindow.left, i, strA);
		pDC->TextOut(rctB.left - m_rctWindow.left, i, strB);
		Sleep(5);
	}

	pDC->TextOut(rctA.left - m_rctWindow.left, i,"             ");
	pDC->TextOut(rctB.left - m_rctWindow.left, i,"             ");

	m_strX = strA;
	m_strY = strB;
	if(codeNumber == 2)
	{
		pDC->MoveTo(rctX.left - m_rctWindow.left - 20, rctX.top - m_rctWindow.top);
		pDC->LineTo(rctA.left - m_rctWindow.left - 20 , rctA.bottom - m_rctWindow.top);
		pDC->LineTo(rctA.left - m_rctWindow.left - 20 - 5 , rctA.bottom - m_rctWindow.top + 12);
		pDC->MoveTo(rctA.left - m_rctWindow.left - 20 , rctA.bottom - m_rctWindow.top);
		pDC->LineTo(rctA.left - m_rctWindow.left - 20 + 5 , rctA.bottom - m_rctWindow.top + 12);

		pDC->MoveTo(rctY.right - m_rctWindow.left + 20, rctY.top - m_rctWindow.top);
		pDC->LineTo(rctB.right - m_rctWindow.left + 20 , rctB.bottom - m_rctWindow.top);
		pDC->LineTo(rctB.right - m_rctWindow.left + 20 - 5 , rctB.bottom - m_rctWindow.top +12);
		pDC->MoveTo(rctB.right - m_rctWindow.left + 20 , rctB.bottom - m_rctWindow.top);
		pDC->LineTo(rctB.right - m_rctWindow.left + 20 + 5 , rctB.bottom - m_rctWindow.top +12);
	}

⌨️ 快捷键说明

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