📄 hexviewerview.cpp
字号:
// HexViewerView.cpp : implementation of the CHexViewerView class
//
#include "stdafx.h"
#include "HexViewer.h"
#include "HexViewerDoc.h"
#include "HexViewerView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CHexViewerView
IMPLEMENT_DYNCREATE(CHexViewerView, CScrollView)
BEGIN_MESSAGE_MAP(CHexViewerView, CScrollView)
// 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()
// CHexViewerView construction/destruction
CHexViewerView::CHexViewerView()
{
memset(&m_logfont, 0, sizeof(m_logfont));
m_nPointSize = 120;
_tcscpy(m_logfont.lfFaceName, _T("Fixedsys"));
CWindowDC dc(NULL);
m_logfont.lfHeight = ::MulDiv(m_nPointSize, dc.GetDeviceCaps(LOGPIXELSY), 720);
m_logfont.lfPitchAndFamily = FIXED_PITCH;
m_pFont = new CFont;
m_pFont->CreateFontIndirect(&m_logfont);
}
CHexViewerView::~CHexViewerView()
{
if (m_pFont != NULL)
{
delete m_pFont;
}
}
BOOL CHexViewerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
// CHexViewerView drawing
void CHexViewerView::OnDraw(CDC* pDC)
{
CHexViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CString strRender;
CFont* pOldFont;
CSize ScrolledSize;
int nStartLine;
int nHeight;
CRect ScrollRect;
CPoint ScrolledPos = GetScrollPosition();
CRect rectClient;
GetClientRect(&rectClient);
// figure out how high each line is
pOldFont = pDC->SelectObject(m_pFont);
nHeight = MeasureFontHeight(m_pFont, pDC);
// find a starting line based on scrolling
ScrolledSize = CSize(rectClient.Width(), rectClient.Height());
ScrollRect = CRect(rectClient.left, ScrolledPos.y,
rectClient.right,
ScrolledSize.cy + ScrolledPos.y);
nStartLine = ScrolledPos.y/16;
// make sure we are drawing where we should
ScrollRect.top = nStartLine*nHeight;
if (pDoc->m_pFile != NULL)
{
int nLine;
for (nLine = nStartLine; ScrollRect.top < ScrollRect.bottom; nLine++)
{
if (!pDoc->ReadLine(strRender, 16, nLine*16))
break;
nHeight = pDC->DrawText(strRender, -1,
&ScrollRect, DT_TOP | DT_NOPREFIX | DT_SINGLELINE);
ScrollRect.top += nHeight;
}
}
pDC->SelectObject(pOldFont);
}
void CHexViewerView::OnInitialUpdate()
{
CHexViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CSize sizeTotal(0, pDoc->m_lFileSize);
SetScrollSizes(MM_TEXT, sizeTotal);
CScrollView::OnInitialUpdate();
}
// CHexViewerView printing
BOOL CHexViewerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CHexViewerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CHexViewerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
// CHexViewerView diagnostics
#ifdef _DEBUG
void CHexViewerView::AssertValid() const
{
CScrollView::AssertValid();
}
void CHexViewerView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CHexViewerDoc* CHexViewerView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHexViewerDoc)));
return (CHexViewerDoc*)m_pDocument;
}
#endif //_DEBUG
// CHexViewerView message handlers
int CHexViewerView::MeasureFontHeight(CFont* pFont, CDC* pDC)
{
// how tall is the identified font in the identified DC?
CFont* pOldFont;
pOldFont = pDC->SelectObject(pFont);
CRect rectDummy;
CString strRender = _T("1234567890ABCDEF- ");
int nHeight = pDC->DrawText(strRender, -1, rectDummy,
DT_TOP | DT_SINGLELINE | DT_CALCRECT);
pDC->SelectObject(pOldFont);
return nHeight;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -