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

📄 hexsho~2.cpp

📁 visual c++ 时尚编程百例 全部源代码
💻 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
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

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

CHexShowView::CHexShowView()
{
	// TODO: add construction code here
	// 选择字体
	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;
	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;
	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();
	CHexShowDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	CSize sizeTotal(0,pDoc->m_lFileLength);

	//CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CHexShowView printing

BOOL CHexShowView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CHexShowView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CHexShowView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// 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 + -