📄 test_fontdlg.cpp
字号:
// Test_FontDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Test_Font.h"
#include "Test_FontDlg.h"
#include "ShowGBK.h"
#include "ShowLatin.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTest_FontDlg dialog
CTest_FontDlg::CTest_FontDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTest_FontDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTest_FontDlg)
m_sUnicode = _T("0");
m_sGBK = _T("0");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTest_FontDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTest_FontDlg)
DDX_Text(pDX, IDC_EDIT1, m_sUnicode);
DDX_Text(pDX, IDC_EDIT2, m_sGBK);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTest_FontDlg, CDialog)
//{{AFX_MSG_MAP(CTest_FontDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest_FontDlg message handlers
BOOL CTest_FontDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = 40;
lstrcpy(lf.lfFaceName, _T("Tahoma"));
m_font.CreateFontIndirect(&lf); // Create the font.
//
// CClientDC dc(this);
// dc.SelectObject(&m_font);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTest_FontDlg::OnButton1()
{
// TODO: Add your control notification handler code here
RECT rect;
CDC* hdc;
TCHAR txt[8];
TCHAR* pt = _T("足够");
txt[0] = 0x9FA5;
txt[1] = 0x9FA6;
txt[2] = 0x0031;
txt[3] = 0x0031;
txt[4] = pt[0];
txt[5] = 0xE4DE;
txt[6] = 0xE4DF;
txt[7] = 0x0000;
hdc = this->GetDC();
rect.left = 10;
rect.top = 10;
rect.right = 210;
rect.bottom = 90;
hdc->DrawText(txt, -1, &rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
char* pcConst = "a足够了0000";
char pcTest[20];
strcpy(pcTest, pcConst);
pcTest[1] = 0xAA;
pcTest[2] = 0xA1;
pcTest[3] = 0xAA;
pcTest[4] = 0xB3;
pcTest[5] = 0x84;
pcTest[6] = 0x20;
pcTest[7] = 0xA0;
pcTest[8] = 0xFE;
rect.left = 10;
rect.top = 40;
rect.right = 210;
rect.bottom = 90;
MultiByteToWideChar(CP_ACP | CP_OEMCP, 0, pcTest, -1, txt, 8);
hdc->DrawText(txt, -1, &rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
int CTest_FontDlg::Char2Int(char* cCode)
{
int i;
/*
if (cCode[0] > '9')
{
i = (cCode[0] - 'a' + 10) * 0x1000;
}
else
{
i = (cCode[0] - '0') * 0x1000;
}
if (cCode[1] > '9')
{
i += (cCode[1] - 'a' + 10) * 0x100;
}
else
{
i += (cCode[1] - '0') * 0x100;
}
if (cCode[2] > '9')
{
i += (cCode[2] - 'a' + 10) * 0x10;
}
else
{
i += (cCode[2] - '0') * 0x10;
}
if (cCode[3] > '9')
{
i += (cCode[3] - 'a' + 10) * 0x1;
}
else
{
i += (cCode[3] - '0') * 0x1;
}
*/
i = 0;
sscanf(cCode, "%x", &i);
return i;
}
void CTest_FontDlg::OnButton2()
{
// TODO: Add your control notification handler code here
RECT rect;
CDC* hdc;
TCHAR txt[8];
TCHAR* pt = _T("足够");
char cCode[10];
TCHAR tCode;
UpdateData(TRUE);
m_sUnicode.MakeLower();
wcscpy(txt, m_sUnicode.GetBuffer(4));
WideCharToMultiByte(CP_ACP | CP_OEMCP, 0, txt, -1, cCode, 8, 0, NULL);
//tCode = (TCHAR)atoi(m_sUnicode.GetBuffer(4));
//strupr(cCode);
tCode = (TCHAR)Char2Int(cCode);
txt[0] = tCode;
txt[1] = 0x0000;
txt[2] = 0x0031;
txt[3] = 0x0031;
txt[4] = pt[0];
txt[5] = 0xE000;
txt[6] = 0xE0BC;
txt[7] = 0x0000;
hdc = this->GetDC();
rect.left = 10;
rect.top = 90;
rect.right = 210;
rect.bottom = 150;
CFont* def_font = hdc->SelectObject(&m_font);
hdc->DrawText(_T(" "), -1, &rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
hdc->DrawText(txt, -1, &rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
hdc->SelectObject(def_font);
}
void CTest_FontDlg::OnButton3()
{
// TODO: Add your control notification handler code here
RECT rect;
CDC* hdc;
TCHAR txt[8];
TCHAR* pt = _T("足够");
char cCode[10];
TCHAR tCode;
UpdateData(TRUE);
m_sGBK.MakeLower();
wcscpy(txt, m_sGBK.GetBuffer(4));
WideCharToMultiByte(CP_ACP | CP_OEMCP, 0, txt, -1, cCode, 8, 0, NULL);
//tCode = (TCHAR)atoi(m_sGBK.GetBuffer(4));
//strupr(cCode);
tCode = (TCHAR)Char2Int(cCode);
txt[0] = tCode;
txt[1] = 0x0000;
txt[2] = 0x0031;
txt[3] = 0x0031;
txt[4] = pt[0];
txt[5] = 0xE000;
txt[6] = 0xE0BC;
txt[7] = 0x0000;
hdc = this->GetDC();
rect.left = 10;
rect.top = 90;
rect.right = 210;
rect.bottom = 150;
CFont* def_font = hdc->SelectObject(&m_font);
hdc->DrawText(_T(" "), -1, &rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
cCode[0] = (char)(txt[0] >> 8);
cCode[1] = (char)(txt[0] & 0x00FF);
cCode[2] = 0;
MultiByteToWideChar(CP_ACP | CP_OEMCP, 0, cCode, -1, txt, 8);
hdc->DrawText(txt, -1, &rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
hdc->SelectObject(def_font);
}
BOOL CTest_FontDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if ((pMsg->message == WM_KEYDOWN) &&
(pMsg->wParam == VK_RETURN) )
{
if (GetFocus() == GetDlgItem(IDC_EDIT1))
{
OnButton2();
return FALSE;
}
else if (GetFocus() == GetDlgItem(IDC_EDIT2))
{
OnButton3();
return FALSE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CTest_FontDlg::OnButton4()
{
// TODO: Add your control notification handler code here
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = 80;
lstrcpy(lf.lfFaceName, _T("Arial"));
CFont font1;
font1.CreateFontIndirect(&lf); // Create the font.
CClientDC dc(this);
CFont* def_font = dc.SelectObject(&font1);
dc.ExtTextOut(5, 5, ETO_OPAQUE, NULL, _T("你Hello"), NULL);
dc.SelectObject(def_font);
//def_font->set
font1.DeleteObject();
}
void CTest_FontDlg::OnButton6()
{
// TODO: Add your control notification handler code here
CShowGBK dlg;
dlg.DoModal();
}
void CTest_FontDlg::OnButton5()
{
// TODO: Add your control notification handler code here
CShowLatin dlg;
dlg.DoModal();
}
void CTest_FontDlg::OnButton7()
{
// TODO: Add your control notification handler code here
// IUnknown *pUnknown;
// IDialog *pIntf = NULL;
// HRESULT hResult;
//
// if (CoInitializeEx(NULL, COINIT_MULTITHREADED) != S_OK)
// {
// MessageBox(NULL, _T("Initialize COM library failed!\n"));
// return;
// }
}
#include "ATLBASE.H"
void CTest_FontDlg::OnButton8()
{
// TODO: Add your control notification handler code here
EnableEUDC(FALSE);
//修改注册表
CRegKey rk;
LPCTSTR lp= _T("EUDC");
rk.Create(HKEY_CURRENT_USER, lp);
// if(rk.SetKeyValue(_T("Tahoma"), _T("\\windows\\fonts\\EUDC.TTE"),
// _T("Tahoma")) == ERROR_SUCCESS)
if(rk.SetValue(_T("\\windows\\fonts\\EUDC.TTE"),
_T("Tahoma")) == ERROR_SUCCESS)
{
EnableEUDC(TRUE);
}
rk.Close();
EnableEUDC(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -