📄 bch_codingview.cpp
字号:
// BCH_CodingView.cpp : implementation of the CBCH_CodingView class
//
#include "stdafx.h"
#include "BCH_Coding.h"
#include "BCH_CodingDoc.h"
#include "BCH_CodingView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBCH_CodingView
IMPLEMENT_DYNCREATE(CBCH_CodingView, CScrollView)
BEGIN_MESSAGE_MAP(CBCH_CodingView, CScrollView)
//{{AFX_MSG_MAP(CBCH_CodingView)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBCH_CodingView construction/destruction
CBCH_CodingView::CBCH_CodingView()
{
// TODO: add construction code here
}
CBCH_CodingView::~CBCH_CodingView()
{
}
BOOL CBCH_CodingView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
SetScrollSizes(MM_TEXT, CSize(0, 0));
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CBCH_CodingView drawing
void CBCH_CodingView::OnDraw(CDC* pDC)
{
CBCH_CodingDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (pDoc->LFileData.GetCount() != 0)
{
CString str;
TEXTMETRIC tm;
POSITION pos = pDoc->LFileData.GetHeadPosition();
pDoc->LFileData.GetNext(pos);
uint8_t data = pDoc->LFileData.GetHead();
uint32_t i, j;
uint64_t lines;
if (pDoc->file_size % 16 != 0)
lines = pDoc->file_size / 16 + 1;
else lines = pDoc->file_size / 16;
pDC->GetTextMetrics(&tm);
pDC->SetTextColor(RGB(100, 100, 100));
text_x = 0;
text_y = 0;
char buffer[3];
CString str_temp;
for (i = 0; i < lines; i++)
{
//显示行标
if (i <= 0x0f)
str.Format("00%x0h: ", i);
else if (i > 0x0f && i <= 0xff)
{
itoa(i, buffer, 16);
str_temp = buffer;
str.Format("0%s0h: ", str_temp);
}
else if (i > 0xff && i <= 0x0fff)
{
uint8_t temp = (uint8_t)(i / 256);
itoa(temp, buffer, 16);
str = "0x";
str += buffer;
temp = (uint8_t)(i % 256);
itoa(temp, buffer, 16);
if (temp <= 0x0f)
str += '0';
str += buffer;
str += "0h: ";
}
else str = "";
pDC->TextOut(text_x, text_y, str);
text_x += tm.tmAveCharWidth * 7;
//文件转化成16进制显示
if (i == lines - 1)
{
for (j = 0; j < lines % 16; j++)
{
if (data <= 0x0f) str.Format("0%x", data);
else str.Format("%x", data);
str.MakeUpper();
pDC->TextOut(text_x, text_y, str);
text_x += tm.tmAveCharWidth * 3;
data = pDoc->LFileData.GetAt(pos);
pDoc->LFileData.GetNext(pos);
}
}
else
{
for (j = 0; j < 16; j++)
{
if (data <= 0x0f) str.Format("0%x", data);
else str.Format("%x", data);
str.MakeUpper();
pDC->TextOut(text_x, text_y, str);
text_x += tm.tmAveCharWidth * 3;
data = pDoc->LFileData.GetAt(pos);
pDoc->LFileData.GetNext(pos);
}
}
text_x = 0;
text_y += (uint16_t)tm.tmHeight;
}
}
}
void CBCH_CodingView::UpdateScrollSizes()
{
CClientDC pDC(this);
TEXTMETRIC tm;
pDC.GetTextMetrics(&tm);
CBCH_CodingDoc* pDoc = GetDocument();
if (pDoc == NULL) return;
int x_page, y_page;
CRect rect;
GetClientRect(&rect);
POSITION pos = pDoc->LFileData.GetHeadPosition();
if(pos != NULL)
{
x_total = 54 * tm.tmAveCharWidth; //得到要显示文件的行和列的象素
y_total = max((uint32_t)rect.bottom, tm.tmHeight * (pDoc->file_size / 32 + 1));
CSize sizeTotal(x_total, y_total);
x_page = x_total / 5;
y_page = rect.bottom - tm.tmHeight;
CSize sizePage(x_page, y_page);
CSize sizeLine(tm.tmAveCharWidth, tm.tmHeight);
SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
}
else
return;
}
/////////////////////////////////////////////////////////////////////////////
// CBCH_CodingView diagnostics
#ifdef _DEBUG
void CBCH_CodingView::AssertValid() const
{
CScrollView::AssertValid();
}
void CBCH_CodingView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CBCH_CodingDoc* CBCH_CodingView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBCH_CodingDoc)));
return (CBCH_CodingDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBCH_CodingView message handlers
void CBCH_CodingView::OnSize(UINT nType, int cx, int cy)
{
UpdateScrollSizes();
CScrollView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -