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

📄 memorydlg.cpp

📁 这个也是我们的毕业设计课题
💻 CPP
字号:
// MemoryDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DFYSimulator.h"
#include "MemoryDlg.h"
#include "DFY\MemorySegment.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMemoryDlg dialog


CMemoryDlg::CMemoryDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMemoryDlg::IDD, pParent)
{
	
	//{{AFX_DATA_INIT(CMemoryDlg)
	m_pEditAddrInput=NULL;
	m_nMemPos=0;
	m_strMemPos = _T("");
	//}}AFX_DATA_INIT
}


void CMemoryDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMemoryDlg)
	DDX_Control(pDX, IDC_SCROLLBAR_MEMPOS, m_scrMemPos);
	DDX_Control(pDX, IDC_LIST_DISPLAYMEM, m_listDisplayMem);
	DDX_Text(pDX, IDC_EDIT_MEMORYADDR, m_strMemPos);
	DDV_MaxChars(pDX, m_strMemPos, 5);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMemoryDlg, CDialog)
	//{{AFX_MSG_MAP(CMemoryDlg)
	ON_WM_PAINT()
	ON_WM_MOVE()
	ON_WM_CLOSE()
	ON_WM_VSCROLL()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMemoryDlg message handlers

BOOL CMemoryDlg::OnInitDialog() 
{

	CDialog::OnInitDialog();
	GetParent()->SetActiveWindow();//set the parent window activity
	m_scrMemPos.SetScrollRange(0,65535);//65535
	CString strMemPos;
	strMemPos.Format("%s","0000H");
	m_strMemPos=strMemPos;
	FlushDisplay();
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMemoryDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	try{
		//the return velue of GetDlgItem changed when the 
		//dialog moving or resizing
		//change the Static's color to white
		//write the Stctic's caption
		CEdit* pStaticMemAddr=(CEdit*)GetDlgItem(IDC_STATIC_MEMADDR);//
		
		CRect *lpRect=new CRect();//used to holding temp rect information
		//initialize the MemoryAddress static control
		CBrush brush;
		brush.CreateSolidBrush(RGB(255,255,255));
		CPaintDC staticMemAddrDC(pStaticMemAddr);
		staticMemAddrDC.SetBkColor(RGB(255,255,255));
		pStaticMemAddr->GetClientRect(lpRect);
		staticMemAddrDC.FillRect(lpRect,&brush);
		staticMemAddrDC.TextOut(0,1,"内存地址");
		//change the Edit's color to white
		//write the Edit's caption
		m_pEditAddrInput=(CEdit*)GetDlgItem(IDC_EDIT_MEMORYADDR);
		//add some other code here
		delete lpRect;


	}
	catch(CResourceException *e)
	{
		e->ReportError();
	}
	catch(...)
	{
	}	
	// Do not call CDialog::OnPaint() for painting messages
}

void CMemoryDlg::OnMove(int x, int y) 
{
	CDialog::OnMove(x, y);
	GetParent()->SetActiveWindow();//set the parent window activity
	
}

void CMemoryDlg::OnClose() 
{
	CMainFrame* pFrame=(CMainFrame*)GetParent();
	pFrame->SetMemoryDlg(NULL);
	DestroyWindow();
	CDialog::OnClose();
}
void CMemoryDlg::OnOK()
{
	UpdateData(TRUE);

	int iSize=m_strMemPos.GetLength();
	char c=m_strMemPos.GetAt(iSize-1);
	if(c=='h'||c=='H')//if it means Hex data
	{
	
	}
	else
	{
		m_nMemPos=atoi(m_strMemPos);
	}
	m_scrMemPos.SetScrollPos(m_nMemPos);
	FlushDisplay();
	m_listDisplayMem.SetCurSel(0);


}
void CMemoryDlg::OnCancel()
{
	//judge the input ,it is Hex or Dec
	
}
void CMemoryDlg::FlushDisplay()
{
	m_listDisplayMem.ResetContent();
	UNSHORT uMemAddr=m_nMemPos;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
	uMemAddr+=1;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
	uMemAddr+=1;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
	uMemAddr+=1;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
	uMemAddr+=1;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
	uMemAddr+=1;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
	uMemAddr+=1;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
	uMemAddr+=1;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
	uMemAddr+=1;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
	uMemAddr+=1;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
	uMemAddr+=1;
	if(uMemAddr>=65535)
		return;
	DisplayMem(uMemAddr);
}

void CMemoryDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	USHORT nCurPos=pScrollBar->GetScrollPos();
	switch(nSBCode)
	{
	case SB_LINEDOWN:
		nCurPos+=1;
		if(nCurPos>65535)
			nCurPos=65535;
		break;
	case SB_LINEUP:
		nCurPos-=1;
		if(nCurPos<0)
			nCurPos=0;
		break;
	case SB_PAGEDOWN:
		nCurPos+=11;
		if(nCurPos>65535)
			nCurPos=65535;
		break;
	case SB_PAGEUP:
		nCurPos-=11;
		if(nCurPos<0)
		nCurPos=0;
		break;
	case SB_THUMBPOSITION:
		nCurPos=nPos;
		break;
	case SB_THUMBTRACK:
		nCurPos=nPos;
	break;

	}
	pScrollBar->SetScrollPos(nCurPos);
	m_nMemPos=nCurPos;
	FlushDisplay();
	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}



void CMemoryDlg::DisplayMem(UNSHORT uAddr)
{
	CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
	Memory* pMemory=pApp->GetSimulatorMemory();
	if(pMemory)//if the simulator memory is exist
	{//display the memory data
		WORD wData=0;
		pMemory->ReadMemory(uAddr,wData);
	//format control
		CString strAddr;
		CString strData;
		if(uAddr<16)
			strAddr.Format("000%xH",uAddr);
		else if(uAddr>=16&&uAddr<256)
			strAddr.Format("00%xH",uAddr);
		else if(uAddr>=256&&uAddr<4096)
			strAddr.Format("0%xH",uAddr);
		else
			strAddr.Format("%xH",uAddr);
	
		UNSHORT wData1=(UNSHORT)wData;
		if(wData1<16)
			strData.Format("000%xH",wData1);
		else if(wData1>=16&&wData1<256)
			strData.Format("00%xH",wData1);
		else if(wData1>=256&&wData1<4096)
			strData.Format("0%xH",wData1);
		else
			strData.Format("%xH",wData1);
		CString str;
		str.Format("%-10s%10s",strAddr,strData);
		str.MakeUpper();
		m_listDisplayMem.AddString(str);
	}
	else
	{
		MessageBox("the simulator memory is not \ninitialize correctly\nor not exist.");
	}
}

⌨️ 快捷键说明

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