📄 bch_codedview.cpp
字号:
// BCH_CodedView.cpp : implementation file
//
#include "stdafx.h"
#include "BCH_Coding.h"
#include "BCH_CodedView.h"
#include "BCH_CodedFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// BCH_CodedView
IMPLEMENT_DYNCREATE(BCH_CodedView, CScrollView)
BCH_CodedView::BCH_CodedView()
{
}
BCH_CodedView::~BCH_CodedView()
{
}
BEGIN_MESSAGE_MAP(BCH_CodedView, CScrollView)
//{{AFX_MSG_MAP(BCH_CodedView)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// BCH_CodedView drawing
void BCH_CodedView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
void BCH_CodedView::OnDraw(CDC* pDC)
{
CBCH_CodingDoc* pDoc = (CBCH_CodingDoc*)GetDocument();
CBCH_CodingApp* APP = (CBCH_CodingApp*)AfxGetApp();
ASSERT_VALID(pDoc);
uint8_t* data;
if (APP->IsFileCoded == TRUE)
{
int i, j;
uint64_t lines;
uint8_t k;
CString str;
TEXTMETRIC tm;
if (pDoc->f_BCH.GetLength() % 32 != 0)
lines = pDoc->f_BCH.GetLength() / 32 + 1;
else lines = pDoc->f_BCH.GetLength() / 32;
pDC->GetTextMetrics(&tm);
pDC->SetTextColor(RGB(100, 100, 100));
text_x = 0;
text_y = 0;
pDoc->f_BCH.SeekToBegin();
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 < (uint64_t)(pDoc->f_BCH.GetLength() % 32 / 2); j++)
{
for (k = 0; k < 2; k++) //每两个字节作为一个码字
{
pDoc->f_BCH.Read(data, 1);
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 * 2;
}
text_x += tm.tmAveCharWidth;
}
}
else
{
for (j = 0; j < 16; j++)
{
for (k = 0; k < 2; k++)
{
pDoc->f_BCH.Read(data, 1);
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 * 2;
}
text_x += tm.tmAveCharWidth;
}
}
text_x = 0;
text_y += (uint16_t)tm.tmHeight;
}
}
}
/////////////////////////////////////////////////////////////////////////////
// BCH_CodedView diagnostics
#ifdef _DEBUG
void BCH_CodedView::AssertValid() const
{
CScrollView::AssertValid();
}
void BCH_CodedView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// BCH_CodedView message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -