📄 fontdlg.cpp
字号:
// FontDlg.cpp : implementation file
//
#include "stdafx.h"
#include "resourceeditor.h"
#include "FontDlg.h"
#include "FileDlg.h"
#include "MMIRes.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const _TCHAR CFontDlg::SZ_EXT[] = _T(".lib");
const _TCHAR CFontDlg::SZ_FILTER[] = _T("Font lib (*.lib)|*.lib|All Files (*.*)|*.*||");
const _TCHAR * CFontDlg::m_arrType[] = {
{_T("SONG_FONT_8")},
{_T("SONG_FONT_10")},
{_T("SONG_FONT_12")},
{_T("SONG_FONT_14")},
{_T("SONG_FONT_16")},
{_T("ASC_ME_FONT_38")},
{_T("ARI_NARROW_FONT_29")},
};
/////////////////////////////////////////////////////////////////////////////
// CFontDlg dialog
CFontDlg::CFontDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFontDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFontDlg)
m_strAscii = _T("");
m_strChinese = _T("");
m_strID = _T("");
m_nType = 0;
//}}AFX_DATA_INIT
m_bEdit = FALSE;
}
void CFontDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFontDlg)
DDX_Text(pDX, IDC_EDT_ASCII, m_strAscii);
DDX_Text(pDX, IDC_EDT_CHINESE, m_strChinese);
DDX_Text(pDX, IDC_EDT_ID, m_strID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFontDlg, CDialog)
//{{AFX_MSG_MAP(CFontDlg)
ON_BN_CLICKED(IDC_BTN_ASCII, OnBtnAscii)
ON_BN_CLICKED(IDC_BTN_CHINESE, OnBtnChinese)
ON_CBN_SELCHANGE(IDC_CMB_TYPE, OnSelchangeCmbType)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFontDlg message handlers
BOOL CFontDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
if( !g_theApp.IsSuperUser() || m_bEdit )
{
CWnd * pWnd = GetDlgItem(IDC_EDT_ID);
_ASSERTE( pWnd != NULL );
pWnd->EnableWindow(FALSE);
pWnd = GetDlgItem(IDC_CMB_TYPE);
_ASSERTE( pWnd != NULL );
pWnd->EnableWindow(FALSE);
}
CComboBox * pCmb = (CComboBox * )GetDlgItem(IDC_CMB_TYPE);
_ASSERTE( pCmb != NULL );
int nCount = sizeof(m_arrType) / sizeof(m_arrType[0]);
for( int i = 0; i < nCount; ++i )
{
pCmb->AddString(m_arrType[i]);
}
if( m_bEdit )
{
_ASSERTE( !m_strID.IsEmpty() );
for( int i = 0; i < nCount; ++i )
{
if( m_strID.CompareNoCase(m_arrType[i]) == 0 )
m_nType = i;
}
}
else
{
m_strID = m_arrType[m_nType];
}
pCmb->SetCurSel(m_nType);
if( m_nType == ASC_ME_FONT_38 || m_nType == ARI_NARROW_FONT_29 )
{
CWnd * pWnd = GetDlgItem(IDC_BTN_CHINESE);
_ASSERTE( pWnd != NULL );
pWnd->EnableWindow(FALSE);
}
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CFontDlg::OnBtnAscii()
{
// TODO: Add your control notification handler code here
CFileDlg dlg;
dlg.SetFileExt(SZ_EXT);
dlg.SetFileFilter(SZ_FILTER);
m_strAscii = dlg.GetPathName();
UpdateData(FALSE);
}
void CFontDlg::OnBtnChinese()
{
// TODO: Add your control notification handler code here
CFileDlg dlg;
dlg.SetFileExt(SZ_EXT);
dlg.SetFileFilter(SZ_FILTER);
m_strChinese = dlg.GetPathName();
UpdateData(FALSE);
}
void CFontDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData();
CComboBox * pCmb = (CComboBox * )GetDlgItem(IDC_CMB_TYPE);
_ASSERTE( pCmb != NULL );
m_nType = pCmb->GetCurSel();
if( g_theApp.IsSuperUser() && !m_bEdit )
{
if( m_strID.IsEmpty() )
{
AfxMessageBox(_T("The ID isn't empty!"));
return;
}
if( m_strID[0] >= _T('0') && m_strID[0] <= _T('9') )
{
AfxMessageBox(_T("The ID's first character can't be a number!"));
return;
}
CMMIRes &mmires = g_theApp.m_MMIRes;
if( mmires.FontIsExist(m_strID) )
{
AfxMessageBox(_T("This ID already exist!"));
return;
}
}
if( m_nType == ASC_ME_FONT_38 || m_nType == ARI_NARROW_FONT_29 )
{
// 两种特殊的字体,不需要汉字库
if( m_strAscii.IsEmpty() )
{
AfxMessageBox(_T("Ascii font db isn't empty!"));
return;
}
}
else
{
if( m_strAscii.IsEmpty() || m_strChinese.IsEmpty() )
{
AfxMessageBox(_T("'Ascii font db' and 'Chinese font db' isn't empty!"));
return;
}
}
CDialog::OnOK();
}
BOOL CFontDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
CWnd * pWnd = GetDlgItem(IDC_EDT_ID);
_ASSERTE( pWnd != NULL );
CWnd * pFocus = GetFocus();
if( pMsg->message == WM_CHAR && pFocus != NULL && pFocus->m_hWnd == pWnd->m_hWnd )
{
_TCHAR cInput = pMsg->wParam;
if( cInput < _T('0') || cInput > _T('9') )
{
if( cInput < _T('a') || cInput > _T('z') )
{
if( cInput != _T('_') && (cInput < _T('A') || cInput > _T('Z')) )
{
if( !(GetKeyState(VK_LCONTROL) & 0x0100) )
return TRUE;
}
}
else
{
pMsg->wParam -= 32;
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CFontDlg::OnSelchangeCmbType()
{
// TODO: Add your control notification handler code here
CComboBox * pCmb = (CComboBox * )GetDlgItem(IDC_CMB_TYPE);
_ASSERTE( pCmb != NULL );
pCmb->GetWindowText(m_strID);
CWnd * pWnd = GetDlgItem(IDC_EDT_ID);
_ASSERTE( pWnd != NULL );
pWnd->SetWindowText(m_strID);
m_nType = pCmb->GetCurSel();
if( m_nType == ASC_ME_FONT_38 || m_nType == ARI_NARROW_FONT_29 )
{
CWnd * pWnd = GetDlgItem(IDC_BTN_CHINESE);
_ASSERTE( pWnd != NULL );
pWnd->EnableWindow(FALSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -