⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fonttestdlg.cpp

📁 万能字库生成工具: 将UNICODE
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/***********************************************************************************
注意:
	1. 在程序编译时要注意对UNICODE码的支持(就是要添加宏:_UNICODE);
	2. 在"Setting/link/Customize"中添加 :/nologo /entry:"wWinMainCRTStartup" ,
	   否则编译出错;
	3. 将所有编码都转换成相应的unicode码进行显示和操作;
	4. 此函数对于四字节的Uincide或者GB18030缺乏支持,在以后会作以补充; 
 
修改:
	原因:去掉CNumspinCtrl类对象,此类在UNICODE宏作用下比较异常
***********************************************************************************/

#include "stdafx.h"
#include "FontTest.h"
#include "FontTestDlg.h"

#include "..\include\GBKUNICODE.h"
#include "..\include\GBKBIG5.h"
//#include "..\include\OutputHead.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

void CreateFont_Proc(LPVOID lpParam);
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFontTestDlg dialog

CFontTestDlg::CFontTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFontTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFontTestDlg)
	m_strBeginCode = _T("");
	m_nFontHeight = 16;
	m_nFontWidth = 16;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	
	m_nAddOrDelete = -1;
	m_pFont = new BYTE[TEST_CODE_LENGTH];
	memset(m_pFont, 0x00, TEST_CODE_LENGTH*sizeof(BYTE));

	m_nPrevCX = 0;
	m_nPrevCY = 0;

	m_nShowType = 0;

	m_fontHandle = NULL;
	m_dwThreadID = 0;

	m_nMemWidth = LEN_WIDTH_INIT;
	m_nMaxOffset = 0;
	m_nCurHandSel = 0;

	memset(m_byShowBuf, 0x00, TRAN_FILE_BUF_LEN*sizeof(BYTE));
}

void CFontTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFontTestDlg)
	DDX_Control(pDX, IDC_EDIT_SOURCE, m_ctlEditSource);
	DDX_Control(pDX, IDC_COMBO_SOURCE, m_ctlSourceFrom);
	DDX_Control(pDX, IDC_COMBO_FONT, m_ctlFontSel);
	DDX_Control(pDX, IDC_COMBO_FONT_COLOR, m_ctlFontColor);
	DDX_Control(pDX, IDC_SPIN_FONT_WIDTH, m_spinWidth);
	DDX_Control(pDX, IDC_SPIN_FONT_HEIGHT, m_spinHeight);
	DDX_Control(pDX, IDC_COMBO_CODE_TYPE, m_ctlCombox);
	DDX_Control(pDX, IDC_EDIT_CODE, m_ctlCode);
	DDX_Control(pDX, IDC_EDIT_SHOW, m_ctlEdit);
	DDX_Text(pDX, IDC_EDIT_BEGIN_CODE, m_strBeginCode);
	DDV_MaxChars(pDX, m_strBeginCode, 6);
	DDX_Control(pDX, IDC_FONT_CURVE, m_fontCurve);
	DDX_Text(pDX, IDC_EDIT_FONT_HEIGHT, m_nFontHeight);
	DDX_Text(pDX, IDC_EDIT_FONT_WIDTH, m_nFontWidth);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFontTestDlg, CDialog)
	//{{AFX_MSG_MAP(CFontTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
	ON_BN_CLICKED(IDC_BUTTON_NEXT, OnButtonNext)
	ON_BN_CLICKED(IDC_BUTTON_APPLY, OnButtonApply)
	ON_CBN_SELCHANGE(IDC_COMBO_CODE_TYPE, OnSelchangeComboCodeType)
	ON_WM_SIZE()
	ON_EN_CHANGE(IDC_EDIT_FONT_WIDTH, OnChangeEditFontWidth)
	ON_EN_CHANGE(IDC_EDIT_FONT_HEIGHT, OnChangeEditFontHeight)
	ON_BN_CLICKED(IDC_BUTTON_CREATE_FONT, OnCreateFont)
	ON_BN_CLICKED(IDC_BUTTON_SELECT_FILE, OnSelectFile)
	ON_CBN_SELCHANGE(IDC_COMBO_SOURCE, OnSelchangeComboSource)
	ON_BN_CLICKED(IDC_BUTTON_FILE_URL, OnFileUrl)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFontTestDlg message handlers

BOOL CFontTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	CString str;
	str.LoadString(IDS_TITLE);
	SetWindowText(str);

	SetIcon(m_hIcon, TRUE);			 
	SetIcon(m_hIcon, FALSE);

	InitParameter();
	
	return TRUE;  
}

void CFontTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

void CFontTestDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); 

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

HCURSOR CFontTestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


////////////////////////////////////////////////////////////////////////////////
//code self
////////////////////////////////////////////////////////////////////////////////
bool CFontTestDlg::InitParameter()
{
	CString str;
	m_langID = GetUserDefaultLangID();
	if(m_langID == 0x0804)
	{
		str.LoadString(IDS_LANG_CHINESE_PRC);
		GetDlgItem(IDC_EDIT_LANGUAGE) ->SetWindowText(str);
		
		str.LoadString(IDS_RES_UNICODE);
		m_ctlCombox.InsertString(0, (LPCTSTR)str);
		str.LoadString(IDS_RES_GB2312);
		m_ctlCombox.InsertString(1, (LPCTSTR)str);
		str.LoadString(IDS_RES_GBK);
		m_ctlCombox.InsertString(2, (LPCTSTR)str);
		str.LoadString(IDS_RES_GB18030);
		m_ctlCombox.InsertString(3, (LPCTSTR)str);
		str.LoadString(IDS_RES_BIG5);
		m_ctlCombox.InsertString(4, (LPCTSTR)str);

		m_ctlFontSel.SelectString(0, _T("宋体"));
	}
	else if(m_langID == 0x0404)
	{
		str.LoadString(IDS_LANG_CHINESE_TAIWAN);
		GetDlgItem(IDC_EDIT_LANGUAGE) ->SetWindowText(str);

		str.LoadString(IDS_RES_UNICODE);
		m_ctlCombox.InsertString(0, (LPCTSTR)str);
		str.LoadString(IDS_RES_BIG5);
		m_ctlCombox.InsertString(1, (LPCTSTR)str);

		m_ctlFontSel.SelectString(0, _T("Arial"));
	}
	else
	{
		str.LoadString(IDS_LANG_UNSUPPORT);
		GetDlgItem(IDC_EDIT_LANGUAGE) ->SetWindowText(str);

		str.LoadString(IDS_RES_UNICODE);
		m_ctlCombox.InsertString(0, (LPCTSTR)str);

		m_ctlFontSel.SelectString(0, _T("Arial"));
	}

	str.LoadString(IDS_SOURCE_ALL_CODE);
	m_ctlSourceFrom.InsertString(SOURCE_ALL_CODE, str);
	str.LoadString(IDS_SOURCE_HAND_EDIT);
	m_ctlSourceFrom.InsertString(SOURCE_HAND_EDIT, str);
	str.LoadString(IDS_SOURCE_SELECT_FILE);
	m_ctlSourceFrom.InsertString(SOURCE_SELECT_FILE, str);

	m_ctlSourceFrom.SetCurSel(SOURCE_ALL_CODE);
	GetDlgItem(IDC_BUTTON_SELECT_FILE) ->EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_SOURCE) ->EnableWindow(FALSE);
	
	m_ctlCombox.SetCurSel(0);
	m_ctlCombox.GetLBText(0,m_strCodeSel);

	m_pFont[0] = HIBYTE((WORD)UNICODE_BEGIN);
	m_pFont[1] = LOBYTE((WORD)UNICODE_BEGIN);
	ShowInfo();
	
	TCHAR szTemp[4] = {0};
	str.Empty();
	for(int i = 0; i < 2; i++)
	{
		_stprintf(szTemp, _T("%02X"), m_pFont[i]);
		str += szTemp;
	}
	m_strBeginCode = str;
	UpdateData(FALSE);

	//m_spinHeight.SetBuddy(&m_ctlFontHeight);
	//m_spinHeight.SetRange(LEN_WIDTH_MIN,LEN_WIDTH_MAX);
	//m_spinWidth.SetBuddy(&m_ctlFontWidth);
	//m_spinWidth.SetRange(LEN_WIDTH_MIN,LEN_WIDTH_MAX);
	//m_spinHeight.SetPos(LEN_WIDTH_INIT);
	//m_spinHeight.SetDelta(1);
	//m_spinWidth.SetPos(LEN_WIDTH_INIT);
	//m_spinWidth.SetDelta(1);
	
	str.LoadString(IDS_COLOR_SINGLE);
	m_ctlFontColor.InsertString(0, str);
	str.LoadString(IDS_COLOR_MULTICOLOR_8);
	m_ctlFontColor.InsertString(1, str);
	str.LoadString(IDS_COLOR_MULTICOLOR_16);
	m_ctlFontColor.InsertString(2, str);
	str.LoadString(IDS_COLOR_MULTICOLOR_24);
	m_ctlFontColor.InsertString(3, str);
	m_ctlFontColor.SetCurSel(0);

	GetDlgItem(IDC_BUTTON_APPLY) ->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_NEXT) ->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_STOP) ->EnableWindow(FALSE);

	return true;
}

bool CFontTestDlg::ShowInfo()
{
	int nSel = m_ctlSourceFrom.GetCurSel();

	if(nSel == SOURCE_ALL_CODE)
	{
		TCHAR szTemp[4] = {0};
		CString str;
		
		WORD wFont = MAKEWORD(m_pFont[1], m_pFont[0]);
		
		if(m_nAddOrDelete == 0)
			wFont --;
		else if(m_nAddOrDelete == 1)
			wFont ++;
		else if(m_nAddOrDelete == -1)
			wFont += 0;
		
		m_pFont[1] = LOBYTE(wFont);
		m_pFont[0] = HIBYTE(wFont);
		
		str.Empty();
		for(int i = 0; i < 2; i++)
		{
			_stprintf(szTemp, _T("%02X"), m_pFont[i]);
			str += szTemp;
		}
		
		m_ctlCode.SetWindowText(str);
		
		CString strUnicode;
		strUnicode.LoadString(IDS_RES_UNICODE);
		if(m_strCodeSel != strUnicode)
		{
			CString strBig5, strGB2312, strGBK, strGB18030;
			strBig5.LoadString(IDS_RES_BIG5);
			strGB2312.LoadString(IDS_RES_GB2312);
			strGBK.LoadString(IDS_RES_GBK);
			strGB18030.LoadString(IDS_RES_GB18030);
			
			TCHAR tsFont[TEST_CODE_LENGTH]= {0};
			BYTE tempBuf[TEST_CODE_LENGTH]= {0};
			bool bTran = false;
			TCHAR tcGBK = 0x0000;
			TCHAR tcBig5 = 0x0000;
			if((m_strCodeSel == strGB2312) ||(m_strCodeSel == strGBK) ||(m_strCodeSel == strGB18030))
			{
				if(m_langID == 0x0404)
				{
					tcGBK = (TCHAR)MAKEWORD(m_pFont[1], m_pFont[0]);
					bTran = TranGBKAndBig5(tcGBK, tcBig5, FROM_GBK_TO_BIG5);
					if(!bTran)
					{
						m_ctlEdit.SetWindowText(_T(""));
						return false;
					}
					else
					{
						tempBuf[0] = HIBYTE((WORD)tcBig5);
						tempBuf[1] = LOBYTE((WORD)tcBig5);
						MultiByteToWideChar(CP_ACP,0,(char*)tempBuf,2,tsFont,1);
					}
				}
				else
				{
					MultiByteToWideChar(CP_ACP,0,(char*)m_pFont,2,tsFont,1);
				}	
			}
			else if(m_strCodeSel == strBig5)
			{
				if(m_langID == 0x0804)
				{
					tcBig5 = (TCHAR)MAKEWORD(m_pFont[1], m_pFont[0]);
					bTran = TranGBKAndBig5(tcGBK, tcBig5, FROM_BIG5_TO_GBK);
					if(!bTran)
					{
						m_ctlEdit.SetWindowText(_T(""));
						return false;
					}
					else
					{
						tempBuf[0] = HIBYTE((WORD)tcGBK);
						tempBuf[1] = LOBYTE((WORD)tcGBK);
						MultiByteToWideChar(CP_ACP,0,(char*)tempBuf,2,tsFont,1);
					}
				}
				else
				{
					MultiByteToWideChar(CP_ACP,0,(char*)m_pFont,2,tsFont,1);
				}
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -