📄 showgbk.cpp
字号:
// ShowGBK.cpp : implementation file
//
#include "stdafx.h"
#include "Test_Font.h"
#include "ShowGBK.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CShowGBK dialog
CShowGBK::CShowGBK(CWnd* pParent /*=NULL*/)
: CDialog(CShowGBK::IDD, pParent)
{
//{{AFX_DATA_INIT(CShowGBK)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pGBK = new char[2048 * 2];
m_pUnicode = new TCHAR[2048];
m_nCurr = 0;
UINT8 GBK[3][4];
int i, j, k, index;
GBK[0][0] = 0xA1;
GBK[0][1] = 0x40;
GBK[0][2] = 0xA7;
GBK[0][3] = 0xA0;
GBK[1][0] = 0xAA;
GBK[1][1] = 0xA1;
GBK[1][2] = 0xAF;
GBK[1][3] = 0xFE;
GBK[2][0] = 0xF8;
GBK[2][1] = 0xA1;
GBK[2][2] = 0xFE;
GBK[2][3] = 0xFE;
index = 0;
for (i=0; i<3; i++)
{
for (j=GBK[i][0]; j<= GBK[i][2]; j++)
{
for (k=GBK[i][1]; k<= GBK[i][3]; k++)
{
m_pGBK[index++] = j;
m_pGBK[index++] = k;
}
}
}
m_pGBK[index] = 0;
m_nChar = index / 2;
MultiByteToWideChar(CP_ACP | CP_OEMCP, 0, m_pGBK, index, m_pUnicode, 2048);
char cInvalid[2];
TCHAR tcInValid;
cInvalid[0] = '?';
cInvalid[1] = 0;
MultiByteToWideChar(CP_ACP | CP_OEMCP, 0, cInvalid, 1, &tcInValid, 1);
for (i=0; i<m_nChar; i++)
{
if (m_pUnicode[i] == tcInValid)
{
memmove(&m_pUnicode[i], &m_pUnicode[i + 1], (m_nChar - i + 1) * 2);
i--;
m_nChar--;
}
}
}
void CShowGBK::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CShowGBK)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CShowGBK, CDialog)
//{{AFX_MSG_MAP(CShowGBK)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShowGBK message handlers
BOOL CShowGBK::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = FONT_HEIGHT;
lstrcpy(lf.lfFaceName, _T("Arial"));
//lstrcpy(lf.lfFaceName, _T("Tahoma"));
m_font.CreateFontIndirect(&lf); // Create the font.
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CShowGBK::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if (m_pGBK)
{
delete m_pGBK;
m_pGBK = NULL;
}
if (m_pUnicode)
{
delete m_pUnicode;
m_pUnicode = NULL;
}
return CDialog::DestroyWindow();
}
void CShowGBK::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
DrawPage(m_nCurr);
// Do not call CDialog::OnPaint() for painting messages
}
void CShowGBK::DrawPage(int nIndex)
{
CClientDC dc(this);
CFont* def_font = dc.SelectObject(&m_font);
TCHAR* ptcSpace = _T(" ");
TCHAR tcClear[CHAR_IN_LINE * 4 +1];
TCHAR tcChar[CHAR_IN_LINE+1];
memset(tcClear, 0, CHAR_IN_LINE * 8 + 2);
memcpy(tcClear, ptcSpace, CHAR_IN_LINE * 8);
for (int j=0; j<LINE_IN_PAGE; j++)
{
dc.ExtTextOut(5, 5 + FONT_HEIGHT * j, ETO_OPAQUE, NULL, tcClear, NULL);
}
for (int i=0; i<LINE_IN_PAGE; i++)
{
if ((nIndex >= m_nChar) || (nIndex < 0))
{
break;
}
memcpy(tcChar, m_pUnicode+nIndex, CHAR_IN_LINE * 2);
nIndex += CHAR_IN_LINE;
tcChar[CHAR_IN_LINE] = 0;
dc.ExtTextOut(5, 5 + FONT_HEIGHT * i, ETO_OPAQUE, NULL, tcChar, NULL);
}
dc.SelectObject(def_font);
}
void CShowGBK::OnButton1()
{
// TODO: Add your control notification handler code here
if (m_nCurr >= (CHAR_IN_LINE * LINE_IN_PAGE))
{
m_nCurr -= CHAR_IN_LINE * LINE_IN_PAGE;
}
DrawPage(m_nCurr);
}
void CShowGBK::OnButton2()
{
// TODO: Add your control notification handler code here
if ((m_nCurr + CHAR_IN_LINE * LINE_IN_PAGE) < m_nChar)
{
m_nCurr += CHAR_IN_LINE * LINE_IN_PAGE;
}
DrawPage(m_nCurr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -