📄 hexshowview.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
//选择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;
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();//add
ASSERT_VALID(pDoc);//add
CSize sizeTotal(0,pDoc->m_lFileLength);//add
//CSize sizeTotal;
// TODO: calculate the total size of this view
//sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CHexShowView printing
//DEL BOOL CHexShowView::OnPreparePrinting(CPrintInfo* pInfo)
//DEL {
//DEL // default preparation
//DEL return DoPreparePrinting(pInfo);
//DEL }
//DEL void CHexShowView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
//DEL {
//DEL // TODO: add extra initialization before printing
//DEL }
//DEL void CHexShowView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
//DEL {
//DEL // TODO: add cleanup after printing
//DEL }
/////////////////////////////////////////////////////////////////////////////
// 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 + -