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

📄 addreaddlg.cpp

📁 一个amccs5933芯片的驱动程序开发源程序和部分文档
💻 CPP
字号:
// AddReadDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Test3042.h"
#include "AddReadDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// AddReadDlg dialog


AddReadDlg::AddReadDlg(CWnd* pParent /*=NULL*/)
	: CDialog(AddReadDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(AddReadDlg)
	m_EvalReadAdd = _T("");
	m_EvalRadioRead = -1;
	m_EvalRadioRdType = -1;
	m_EvalReadLoops = 0;
	//}}AFX_DATA_INIT
}


void AddReadDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(AddReadDlg)
	DDX_Text(pDX, IDC_READ_ADD, m_EvalReadAdd);
	DDV_MaxChars(pDX, m_EvalReadAdd, 4);
	DDX_Radio(pDX, IDC_RD_8_BIT, m_EvalRadioRead);
	DDX_Radio(pDX, IDC_RD_SAME, m_EvalRadioRdType);
	DDX_Text(pDX, IDC_READ_LOOPS, m_EvalReadLoops);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(AddReadDlg, CDialog)
	//{{AFX_MSG_MAP(AddReadDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// AddReadDlg message handlers

BOOL AddReadDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
//	This is now done in MainFrm.cpp. The assignment in here will override the
//  assignment in the MainFrm.cpp file.
//m_EvalRadioRead = 2;	// Default to 32-bit addressing

//	theApp.Out ("In Read Dlg init part.\n");
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void AddReadDlg::OnOK() 
{
	DWORD lastAdd;
	UpdateData(TRUE);

	if (m_EvalReadLoops < 1 || m_EvalReadLoops > 1000000)
	{
		MessageBox ("The number of reads has to be a number between 1 and 1000000.");
		return;
	}

	CString aString("Out of range:\n\tAddress range: 0-");
	switch (m_EvalRadioRead)
	{
	case 0:
		aString += "7fff.";
		lastAdd = 0x7fff;
		break;
	case 1:
		aString += "7ffe.";
		lastAdd = 0x7ffe;
		break;
	case 2:
		aString += "7ffc.";
		lastAdd = 0x7ffc;
		break;
	default:
		MessageBox("Invalid word size. Please select a valid word size.");
		return;
		break;
	}

	if (hex2dec2(m_HexReadAdd, m_EvalReadAdd) == false)
	{
		MessageBox("Invalid input:\n\tPlease enter valid Hex values.");
		return;
	}
	else
	{
		if (m_HexReadAdd < 0 || m_HexReadAdd > lastAdd)
		{
			MessageBox(aString);
			return;
		}
	}
	CDialog::OnOK();
}

// Function converts valid hex input string to an integer.
// Valid input is a string of length 8 with values 0-9 or a-f or A-F.
bool AddReadDlg::hex2dec2(DWORD & outInt, CString inStr)
{
	char tmp;
	DWORD tmpLong = 0, result = 0;
//	theApp.Out("String: %s\tInt init:%x\n",inStr, outInt);
	inStr.MakeLower();	// make all letters lowercase
	inStr.TrimRight();	// get rid of whitespaces
	inStr.TrimLeft();	// get rid of whitespaces

	result = 0;
	for (int i=0; i < inStr.GetLength(); ++i)
	{
		tmpLong = 0;
		tmp = inStr[i];
		switch( tmp )
		{	//NOTE: For some reason, atol() doesn't work properly on some
			// machines. So, I manually did the case statement.
		case '0':	tmpLong = 0;break;
		case '1':	tmpLong = 1;break;
		case '2':	tmpLong = 2;break;
		case '3':	tmpLong = 3;break;
		case '4':	tmpLong = 4;break;
		case '5':	tmpLong = 5;break;
		case '6':	tmpLong = 6;break;
		case '7':	tmpLong = 7;break;
		case '8':	tmpLong = 8;break;
		case '9':	tmpLong = 9;break;
		case 'a':	tmpLong = 10;break;
		case 'b':	tmpLong = 11;break;
		case 'c':	tmpLong = 12;break;
		case 'd':	tmpLong = 13;break;
		case 'e':	tmpLong = 14;break;
		case 'f':	tmpLong = 15;break;
		default:	return false;break;
		}
		result = result + tmpLong;
		if (i < (inStr.GetLength() - 1)) // no need to multiply on the last test
			result = result * 16;
	}
	outInt = result;
//	theApp.Out("String: %s\tInt init:%x\n",inStr, outInt);
	return true;
}

⌨️ 快捷键说明

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