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

📄 hexshowview.cpp

📁 将其他数据结构转化为十六进制存储
💻 CPP
字号:
// HexShowView.cpp : implementation of the CHexShowView class
//

#include "stdafx.h"
#include "HexShow.h"

#include "HexShowDoc.h"
#include "HexShowView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CHexShowView

IMPLEMENT_DYNCREATE(CHexShowView, CScrollView)

BEGIN_MESSAGE_MAP(CHexShowView, CScrollView)
//{{AFX_MSG_MAP(CHexShowView)
// NOTE - the ClassWizard will add and remove mapping macros here.
//    DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHexShowView construction/destruction

CHexShowView::CHexShowView()
{
	// TODO: add construction code here
	//选择一种名为“Fixedsys”的字体,该字体使得字符的排列整齐
	LOGFONT	m_logfont;
	memset(&m_logfont, 0, sizeof(m_logfont));
	_tcscpy(m_logfont.lfFaceName, _T("Fixedsys"));
	CClientDC dc(NULL);
	m_logfont.lfHeight = ::MulDiv
		(120, dc.GetDeviceCaps(LOGPIXELSY), 720);
	m_logfont.lfPitchAndFamily = FIXED_PITCH;
	m_pFont = new CFont;
	m_pFont->CreateFontIndirect(&m_logfont);
	
}

CHexShowView::~CHexShowView()
{if (m_pFont != NULL)
delete m_pFont;

}

BOOL CHexShowView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	
	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CHexShowView drawing

void CHexShowView::OnDraw(CDC* pDC)
{
	CHexShowDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	
	CFont*	pOldFont;
	CString sLine;//用于显示的文本行
	CSize	ScrolledSize;//窗口的客户区的范围
	int	iStartLine;//当前屏第一行显示的行的索引号
	int	nHeight;//输出文本行的高度

	CRect ScrollRect; //获得该屏滚动条的位置 
	CPoint ScrolledPos = GetScrollPosition(); 
	CRect rectClient; GetClientRect(&rectClient); 
	// 求出每行的高度(单位:象素数) 
	TEXTMETRIC tm; //tm用于存储库存字体的参数;
	pDC->GetTextMetrics(&tm); 
	nHeight = tm.tmHeight; 
	pOldFont = pDC->SelectObject(m_pFont); 
	// 根据滚动,求出开始行
	ScrolledSize = CSize(rectClient.Width(), rectClient.Height()); 
	ScrollRect = CRect(rectClient.left, ScrolledPos.y, rectClient.right, ScrolledSize.cy + ScrolledPos.y);
	iStartLine = ScrolledPos.y/16; 
	// make sure we are drawing where we should 
	ScrollRect.top = iStartLine*nHeight; 
	if (pDoc->m_pHexFile != NULL)
	{
		int nLine; 
		for (nLine = iStartLine; ScrollRect.top < ScrollRect.bottom; nLine++)
		{ if (!pDoc->ReadFileAndProcess (sLine, nLine*16))
		break;
		nHeight = pDC->DrawText(sLine, -1, &ScrollRect, DT_TOP | DT_NOPREFIX | DT_SINGLELINE); 
		ScrollRect.top += nHeight; 
		} 
	} 
	pDC->SelectObject(pOldFont);
}

void CHexShowView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
	
	// TODO: calculate the total size of this view
	CScrollView::OnInitialUpdate();
	CHexShowDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	CSize sizeTotal(0, pDoc->m_lFileLength);
	SetScrollSizes(MM_TEXT, sizeTotal);
	
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CHexShowView diagnostics

#ifdef _DEBUG
void CHexShowView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CHexShowView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CHexShowDoc* CHexShowView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHexShowDoc)));
	return (CHexShowDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CHexShowView message handlers

⌨️ 快捷键说明

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