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

📄 simplecaidlg.cpp

📁 我要下载源代码我要源代码我要下载代码我要下载源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}

void CSimpleCAIDlg::MoveXTemp(CClientDC *pDC)
{

	CRect rctX, rctTemp;
	m_edtTemp.GetWindowRect(&rctTemp);
	m_edtX.GetWindowRect(&rctX);
	int i;
	for( i = 20; i < rctX.top - rctTemp.bottom; i++)
	{
		pDC->TextOut(rctX.left - m_rctWindow.left + i , rctX.top - i - m_rctWindow.top, "10");
		Sleep(10);
	}
	pDC->TextOut(rctX.left - m_rctWindow.left + i , rctX.top - i - m_rctWindow.top,"             ");
	m_strTemp = m_strX;
}

void CSimpleCAIDlg::MoveYX(CClientDC *pDC)
{
	CRect rctX, rctY;
	m_edtX.GetWindowRect(&rctX);
	m_edtY.GetWindowRect(&rctY);
	int i;
	for(i=rctY.left - m_rctWindow.left; i > rctX.left - m_rctWindow.left; i--)
	{
		pDC->TextOut(i+10, rctY.top - m_rctWindow.top + 30,"20");
		Sleep(10);
	}
	pDC->TextOut(i+10, rctY.top - m_rctWindow.top + 30,"       ");
	m_strX = m_strY;
}

void CSimpleCAIDlg::MoveTempY(CClientDC *pDC)
{
	CRect rctTemp, rctY;
	m_edtTemp.GetWindowRect(&rctTemp);
	m_edtY.GetWindowRect(&rctY);
	int i;
	for( i= 0; i< rctY.top - rctTemp.bottom -20; i++)
	{
		pDC->TextOut(rctTemp.left - m_rctWindow.left + i , rctTemp.bottom - m_rctWindow.top + i, "10");
		Sleep(10);
	}
	pDC->TextOut(rctTemp.left - m_rctWindow.left + i , rctTemp.bottom - m_rctWindow.top + i,"       ");
	m_strY = m_strTemp;
}
void CSimpleCAIDlg::MoveATemp(CClientDC *pDC)
{

	CRect rctA, rctTemp;
	m_edtTemp.GetWindowRect(&rctTemp);
	m_edtA.GetWindowRect(&rctA);
	int i;
	for( i = 20; i < rctTemp.top - rctA.bottom -20; i++)
	{
		pDC->TextOut(rctA.left - m_rctWindow.left + i , rctA.bottom - m_rctWindow.top + i, m_strA);
		Sleep(10);
	}
	pDC->TextOut(rctA.left - m_rctWindow.left + i , rctA.bottom - m_rctWindow.top + i,"       ");
	m_strTemp = m_strA;
}

void CSimpleCAIDlg::MoveBA(CClientDC *pDC)
{
	CRect rctA, rctB;
	m_edtA.GetWindowRect(&rctA);
	m_edtB.GetWindowRect(&rctB);
	int i;
	for(i=rctB.left - m_rctWindow.left; i > rctA.left - m_rctWindow.left; i--)
	{
		pDC->TextOut(i+10, rctB.top - m_rctWindow.top + 30, m_strB);
		Sleep(10);
	}
	pDC->TextOut(i+10, rctB.top - m_rctWindow.top + 30,"             ");
	m_strA = m_strB;
}

void CSimpleCAIDlg::MoveTempB(CClientDC *pDC)
{
	CRect rctTemp, rctB;
	m_edtTemp.GetWindowRect(&rctTemp);
	m_edtB.GetWindowRect(&rctB);
	int i;
	for( i= 20; i< rctTemp.top - rctB.bottom; i++)
	{
		pDC->TextOut(rctTemp.right - m_rctWindow.left + i -40 , rctTemp.top - m_rctWindow.top - i, m_strTemp);
		Sleep(10);
	}
	pDC->TextOut(rctTemp.right - m_rctWindow.left + i - 40, rctTemp.top - m_rctWindow.top - i,"       ");
	m_strB = m_strTemp;
}

void CSimpleCAIDlg::OutputAB(CClientDC *pDC)
{
	CRect rctCode;
	m_edtCode.GetWindowRect(&rctCode);
	CString strOutput = "a = ";
	strOutput += m_strA;
	strOutput += ", b= ";;
	strOutput += m_strB;
	pDC->TextOut(rctCode.left - m_rctWindow.left +20, rctCode.bottom - m_rctWindow.top + 40, strOutput);
}

void CSimpleCAIDlg::OutputClear(CClientDC *pDC)
{
	CRect rctCode;
	m_edtCode.GetWindowRect(&rctCode);
	pDC->TextOut(rctCode.left - m_rctWindow.left +20, rctCode.bottom - m_rctWindow.top + 40,"                             ");
}

void CSimpleCAIDlg::OnButtonStep() 
{
	// TODO: Add your control notification handler code here
	int lineLength = m_strRemainCode.FindOneOf("\r\n")+2; //当前行的长度
	int remainLength = m_strRemainCode.GetLength() - lineLength;  //余下的程序长度
	CString strTemp = m_strRemainCode.Right(remainLength);        //余下的程序
	m_nStarCharIndex = m_nEndCharIndex;                 //上一行的结束位置是这一行的开始位置
	m_nEndCharIndex = m_nStarCharIndex + lineLength;    //本行的结束位置为本行开始位置加本行长度

	static CString strTempRemain;
	static int nTempStartIndex;
	CClientDC dc(this);
	dc.SetBkColor(GetSysColor(COLOR_3DFACE));
	//根据当前执行程序的行数完成相应的操作
	switch(m_nCodeLine)
	{
	case 0:  
	case 1:
	case 2:
	case 3:	m_nCodeLine++;
			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			break;
	case 4: m_nCodeLine++;
			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			m_stcLableA.ShowWindow(SW_SHOW);
			m_stcLableB.ShowWindow(SW_SHOW);
			m_stcAddrA.ShowWindow(SW_SHOW);
			m_stcAddrB.ShowWindow(SW_SHOW);
			m_edtA.ShowWindow(SW_SHOW);
			m_edtB.ShowWindow(SW_SHOW);
			m_strAddrA = "0x2000";
			m_strAddrB = "0x2002";
			break;
	case 5: m_nCodeLine++;
			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			m_strA = " 10";
							break;
	case 6: m_nCodeLine++;
			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			m_strB = " 20";
			break;
	case 7: 
			m_nCodeLine = 10;
			strTempRemain = m_strRemainCode;
			nTempStartIndex = m_nStarCharIndex;

			lineLength = m_strSwap.FindOneOf("\r\n")+2;
			remainLength = m_strSwap.GetLength() - lineLength;
			strTemp = m_strSwap.Right(remainLength);
			m_strRemainCode = strTemp;

			m_nStarCharIndex = m_strMain.GetLength() + 2;
			m_nEndCharIndex = m_nStarCharIndex + lineLength;

			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			m_stcLableX.ShowWindow(SW_SHOW);
			m_stcLableY.ShowWindow(SW_SHOW);
			m_stcLableTemp.ShowWindow(SW_SHOW);
			m_edtX.ShowWindow(SW_SHOW);
			m_edtY.ShowWindow(SW_SHOW);
			m_edtTemp.ShowWindow(SW_SHOW);
			this->UpdateWindow();

			MoveAXBY(&dc, m_nCodeNumber);
			break;
	case 8: 
			OutputAB(&dc);
			m_nCodeLine ++;
			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			break;
	case 9: 
			OutputClear(&dc);
			Reset();
			return;
			break;
	case 10: 
	case 11: 
	case 12: 
			m_nCodeLine++;
			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			break;
	case 13: 
			if(m_nCodeNumber ==1 )
				MoveXTemp(&dc);
			else
				MoveATemp(&dc);
			m_nCodeLine++;
			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			break;
	case 14: 
			if(m_nCodeNumber ==1 )
				MoveYX(&dc);
			else
				MoveBA(&dc);
			m_nCodeLine++;
			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			break;

	case 15: 
			if(m_nCodeNumber ==1 )
				MoveTempY(&dc);
			else
				MoveTempB(&dc);
			m_nCodeLine++;
			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			break;

	case 16: 
			m_nCodeLine = 8;
			m_strRemainCode = strTempRemain;
			m_nStarCharIndex = nTempStartIndex;

			lineLength = m_strRemainCode.FindOneOf("\r\n")+2;
			remainLength = m_strRemainCode.GetLength() - lineLength;
			strTemp = m_strRemainCode.Right(remainLength);
			m_strRemainCode = strTemp;
			m_nEndCharIndex = m_nStarCharIndex + lineLength;

			m_stcLableX.ShowWindow(SW_HIDE);
			m_stcLableY.ShowWindow(SW_HIDE);
			m_stcLableTemp.ShowWindow(SW_HIDE);
			m_edtX.ShowWindow(SW_HIDE);
			m_edtY.ShowWindow(SW_HIDE);
			m_edtTemp.ShowWindow(SW_HIDE);
			ClearLine();
			this->UpdateWindow();

			m_edtCode.SetSel(m_nStarCharIndex,m_nEndCharIndex);
			break;
	}
	m_strRemainCode = strTemp;

	UpdateData(false);

	m_btnStop.EnableWindow(true);
	m_btnCode1.EnableWindow(false);
	m_btnCode2.EnableWindow(false);

}

void CSimpleCAIDlg::Reset()
{ 
	m_nCodeLine = 0;
	m_nStarCharIndex = 0;
	m_nEndCharIndex = 0;
	m_strA.Empty();
	m_strB.Empty();
	m_strX.Empty();
	m_strY.Empty();
	m_strTemp.Empty();
	m_strRemainCode = m_strEditCode;

	m_stcLableA.ShowWindow(SW_HIDE);
	m_stcLableB.ShowWindow(SW_HIDE);
	m_stcAddrA.ShowWindow(SW_HIDE);
	m_stcAddrB.ShowWindow(SW_HIDE);
	m_edtA.ShowWindow(SW_HIDE);
	m_edtB.ShowWindow(SW_HIDE);
	m_stcLableX.ShowWindow(SW_HIDE);
	m_stcLableY.ShowWindow(SW_HIDE);
	m_stcLableTemp.ShowWindow(SW_HIDE);
	m_edtX.ShowWindow(SW_HIDE);
	m_edtY.ShowWindow(SW_HIDE);
	m_edtTemp.ShowWindow(SW_HIDE);
	m_btnStop.EnableWindow(false);
	m_btnCode1.EnableWindow(true);
	m_btnCode2.EnableWindow(true);
	m_edtCode.SetSel(-1, -1);
	ClearLine();

}

void CSimpleCAIDlg::ClearLine() 
{
	CClientDC dc(this);
	dc.SetBkColor(GetSysColor(COLOR_3DFACE));
	CRect rctA, rctB, rctX, rctY;
	m_edtA.GetWindowRect(&rctA);
	m_edtB.GetWindowRect(&rctB);
	m_edtX.GetWindowRect(&rctX);
	m_edtY.GetWindowRect(&rctY);
	int i;
	for(i=rctA.bottom - m_rctWindow.top; i<rctX.top - m_rctWindow.top;i++)
	{
		dc.TextOut( rctX.left - m_rctWindow.left - 25, i, "        ");
		dc.TextOut( rctY.right - m_rctWindow.left + 15, i, "        ");
	}
}

void CSimpleCAIDlg::OnButtonStop() 
{
	// TODO: Add your control notification handler code here
	Reset();
}

void CSimpleCAIDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	this->GetClientRect(&m_rctWindow);
	ClientToScreen(&m_rctWindow);
	
}

void CSimpleCAIDlg::OnMove(int x, int y) 
{
	CDialog::OnMove(x, y);
	
	// TODO: Add your message handler code here
	this->GetClientRect(&m_rctWindow);
	ClientToScreen(&m_rctWindow);
	
}

HBRUSH CSimpleCAIDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

⌨️ 快捷键说明

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