// CharDlg.cpp : implementation file // #include "stdafx.h" #include "CharDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CCharDlg dialog static int g_nTypeIndex = 0; char CCharDlg::m_charGreece[][3] = { "Α","Β","Γ","Δ","Ε","Ζ","Η", "Θ","Ι","Κ","Λ","Μ","Ν","Ξ", "Ο","Π","Ρ","Σ","Τ","Υ","Φ", "Χ","Ψ","Ω","α","β","γ","δ", "ε","ζ","η","θ","ι","κ","λ", "μ","ν","ξ","ο","π","ρ","σ", "τ","υ","φ","χ","ψ","ω"}; char CCharDlg::m_charMath[][3] = { "≈","≡","=","≤","≥","<",">", "≮","≯","∷","±","+","-","×", "÷","/","∫","∮","∝","∞","∧", "∨","∑","∏","∪","∩","∈","∵", "∴","⊥","∥","∠","⌒","⊙","≌", "∽","√"}; char CCharDlg::m_charSerial[][3] = { "⒈","⒉","⒊","⒋","⒌","⒍","⒎", "⒏","⒐","⒑","⒒","⒓","⒔","⒕", "⒖","⒗","⒘","⒙","⒚","⒛","⑴", "⑵","⑶","⑷","⑸","⑹","⑺","⑻", "⑼","⑽","⑾","⑿","⒀","⒁","⒂", "⒃","⒄","⒅","⒆","⒇","①","②", "③","④","⑤","⑥","⑦","⑧","⑨", "⑩","㈠","㈡","㈢","㈣","㈤","㈥", "㈦","㈧","㈨","㈩"}; char CCharDlg::m_charRomaSerial[][3] = { "Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ","Ⅵ","Ⅶ", "Ⅷ","Ⅸ","Ⅹ","Ⅺ","Ⅻ","ⅰ","ⅱ", "ⅲ","ⅳ","ⅴ","ⅵ","ⅶ","ⅷ","ⅸ", "ⅹ"}; char CCharDlg::m_charInterpunction[][3] = { "。",",","、",";",":","?","!", ".","∶","…","—","·","ˉ","ˇ", "‘","’","“","”","々","~","‖", ""","'","`","|","〃","¨","〔", "〕","〈","〉","《","》","「","」", "『","』","〖","〗","【","】","(", ")","[","]","{","}"}; char CCharDlg::m_charSpecific[][3] = { "°","′","″","$","£","¥","‰", "%","℃","¤","¢","§","№","☆", "★","○","●","◎","◇","◆","□", "■","△","▲","※","→","←","↑", "↓","〓","#","&","@","\","^", "_"," ̄", "▼", "▽"}; CCharDlg::CCharDlg(CWnd* pParent /*=NULL*/) : CDialog(CCharDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCharDlg) m_character = _T(""); //}}AFX_DATA_INIT m_left = -1; m_top = -1; } CCharDlg::~CCharDlg() { delete m_pFont; } void CCharDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCharDlg) DDX_Control(pDX, IDC_COMBO_TYPE, m_combo_type); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCharDlg, CDialog) //{{AFX_MSG_MAP(CCharDlg) ON_WM_PAINT() ON_WM_LBUTTONUP() ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnSelchangeComboType) ON_WM_LBUTTONDBLCLK() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCharDlg message handlers BOOL CCharDlg::OnInitDialog() { CDialog::OnInitDialog(); m_indexCombo = 0; m_countChar = 48; CRect rect; CWnd* pWnd = GetDlgItem(IDC_STATIC_FRAME); CDC *pDC = pWnd->GetDC(); pWnd->GetClientRect(rect); m_wndWidth = rect.Width(); m_wndHeight = rect.Height(); m_Hdistance = m_wndWidth / 10; m_Vdistance = m_wndHeight / 6; m_pFont = new CFont; m_pFont->CreateFont(rect.bottom - rect.top, 0, 0, 0, 700, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH&FF_SWISS, _T("Arial")); m_combo_type.SetCurSel(g_nTypeIndex); OnSelchangeComboType(); UpdateData(false); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CCharDlg::writechar(char pchar[][3],int count) { CWnd* pWnd=GetDlgItem(IDC_STATIC_FRAME); CDC *pDC = pWnd->GetDC(); CFont *pOldFont; CFont *pLargeFont=new CFont; pLargeFont->CreateFont(28, 0, 0, 0, 700, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH&FF_SWISS, _T("Arial")); pOldFont=(CFont *)pDC->SelectObject(pLargeFont); int i = 0 - (int)(m_Hdistance / 1.1); int l = 0 - (int)(m_Vdistance / 1.1); for(int n = 0; n < count; n++) { if(n % 10 == 0) { i = 0 - int(m_Hdistance / 1.1); l = l + m_Vdistance; } pDC->TextOut(i = i + m_Hdistance, l, pchar[n]); } pDC->SelectObject(pOldFont); delete pLargeFont; } void CCharDlg::OnPaint() { CPaintDC dc(this); // device context for painting CRect rect; CWnd* pWnd = GetDlgItem(IDC_STATIC_FRAME); pWnd->GetClientRect(rect); CDC *pDC = pWnd->GetDC(); CBrush* pNewBrush = new CBrush; pNewBrush->CreateSolidBrush(RGB(255, 255, 255)); CBrush* pOldBrush = pDC->SelectObject(pNewBrush); pDC->Rectangle(rect); pDC->SelectObject(pOldBrush); delete pNewBrush; drawPane(); switch(m_indexCombo) { case 0: writechar(m_charGreece, m_countChar); break; case 1: writechar(m_charMath, m_countChar); break; case 2: writechar(m_charRomaSerial, m_countChar); break; case 3: writechar(m_charSerial, m_countChar); break; case 4: writechar(m_charInterpunction, m_countChar); break; case 5: writechar(m_charSpecific, m_countChar); break; } if(m_left >= 0 && m_top >= 0) { drawSmallPane(); } // Do not call CDialog::OnPaint() for painting messages } BOOL CCharDlg::Check(CPoint point) { CRect rect; CWnd* pWnd = GetDlgItem(IDC_STATIC_FRAME); pWnd->GetWindowRect(rect); ScreenToClient(&rect); CRgn* myRgn=new CRgn(); myRgn->CreateRectRgnIndirect(rect); if(myRgn->PtInRegion(point)) { int i,j; i = point.x / m_Hdistance - 1; j = point.y / m_Vdistance - 1; i = j * 10 + i; switch(m_indexCombo) { case 0: if(i < 48) m_character = m_charGreece[i]; else m_character = ""; break; case 1: if(i < 40) m_character=m_charMath[i]; else m_character = ""; break; case 2: if(i < 22) m_character = m_charRomaSerial[i]; else m_character = ""; break; case 3: if(i < 60) m_character = m_charSerial[i]; else m_character = ""; break; case 4: if(i < 47) m_character = m_charInterpunction[i]; else m_character = ""; break; case 5: if(i < 39) m_character = m_charSpecific[i]; else m_character = ""; break; } } else return FALSE; delete myRgn; return TRUE; } void CCharDlg::OnLButtonDblClk(UINT nFlags, CPoint point) { if(!Check(point)) return; g_nTypeIndex = m_combo_type.GetCurSel(); CDialog::OnLButtonDblClk(nFlags, point); CDialog::OnOK(); } void CCharDlg::OnLButtonUp(UINT nFlags, CPoint point) { if(!Check(point)) return; CRect rect; CWnd* pWnd=GetDlgItem(IDC_STATIC_FRAME); pWnd->GetWindowRect(rect); ScreenToClient(&rect); if(m_left >= 0 && m_top >= 0) delSmallPane(); m_left = ((point.x - rect.left) / m_Hdistance) * m_Hdistance; m_top = ((point.y - rect.top) / m_Vdistance) * m_Vdistance; drawSmallPane(); CRect rect2; pWnd->GetClientRect(rect2); CDC *pDC = pWnd->GetDC(); pDC->MoveTo(rect2.right - 1, rect2.top); //画边粗线 pDC->LineTo(rect2.right - 1, rect2.bottom); pDC->MoveTo(rect2.left, rect2.bottom - 1); pDC->LineTo(rect2.right, rect2.bottom - 1); CDialog::OnLButtonUp(nFlags, point); } void CCharDlg::drawPane() { CWnd* pWnd=GetDlgItem(IDC_STATIC_FRAME); CDC *pDC = pWnd->GetDC(); int i, j; m_pen.DeleteObject(); m_pen.CreatePen(PS_SOLID, 1, RGB(0 , 0 ,0)); pDC->SelectObject(m_pen); for(j = 0; j <= m_wndHeight; j = j + m_Vdistance) { pDC->MoveTo(0, j); pDC->LineTo(m_wndWidth, j); } for(i = 0; i <= m_wndWidth ; i = i + m_Hdistance) { pDC->MoveTo(i, 0); pDC->LineTo(i, m_wndHeight); } } void CCharDlg::drawSmallPane() { CWnd* pWnd=GetDlgItem(IDC_STATIC_FRAME); CDC *pDC = pWnd->GetDC(); m_pen.DeleteObject(); m_pen.CreatePen(PS_SOLID,1,RGB(0, 0, 0)); pDC->SelectObject(m_pen); pDC->MoveTo(m_left + m_Hdistance, m_top + 1); pDC->LineTo(m_left + 1, m_top + 1); pDC->LineTo(m_left + 1, m_top + m_Vdistance); m_pen.DeleteObject(); m_pen.CreatePen(PS_SOLID,2,RGB(220, 220, 220)); pDC->SelectObject(m_pen); pDC->MoveTo(m_left + m_Hdistance - 1, m_top + 1); pDC->LineTo(m_left + m_Hdistance -1, m_top + m_Vdistance -1 ); pDC->LineTo(m_left + 1, m_top + m_Vdistance -1 ); m_pen.DeleteObject(); m_pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 255)); pDC->SelectObject(m_pen); pDC->MoveTo(m_left, m_top); pDC->LineTo(m_left, m_top + m_Vdistance); pDC->LineTo(m_left + m_Hdistance, m_top + m_Vdistance); pDC->LineTo(m_left + m_Hdistance, m_top); pDC->LineTo(m_left, m_top); } void CCharDlg::delSmallPane() { CWnd* pWnd=GetDlgItem(IDC_STATIC_FRAME); CDC *pDC = pWnd->GetDC(); m_pen.DeleteObject(); m_pen.CreatePen(PS_SOLID,2,RGB(255, 255, 255)); pDC->SelectObject(m_pen); pDC->MoveTo(m_left + m_Hdistance, m_top + 1); pDC->LineTo(m_left + 1, m_top + 1); pDC->LineTo(m_left + 1, m_top + m_Vdistance); pDC->MoveTo(m_left + m_Hdistance - 1, m_top + 1); pDC->LineTo(m_left + m_Hdistance -1, m_top + m_Vdistance -1 ); pDC->LineTo(m_left + 1, m_top + m_Vdistance -1 ); m_pen.DeleteObject(); m_pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); pDC->SelectObject(m_pen); pDC->MoveTo(m_left , m_top); pDC->LineTo(m_left, m_top + m_Vdistance); pDC->LineTo(m_left + m_Hdistance, m_top + m_Vdistance); pDC->LineTo(m_left + m_Hdistance, m_top); pDC->LineTo(m_left, m_top); } void CCharDlg::OnSelchangeComboType() { if(m_left >= 0 && m_top >= 0) delSmallPane(); m_left = -1, m_top = -1; switch( m_combo_type.GetCurSel() ) { case 0 : m_indexCombo = 0; m_countChar = 48; OnPaint(); break; case 1 : m_indexCombo = 1; m_countChar = 40; OnPaint(); break; case 2 : m_indexCombo = 2; m_countChar = 22; OnPaint(); break; case 3 : m_indexCombo = 3; m_countChar = 60; OnPaint(); break; case 4 : m_indexCombo = 4; m_countChar = 47; OnPaint(); break; case 5 : m_indexCombo = 5; m_countChar = 39; OnPaint(); break; } } void CCharDlg::OnCancel() { m_character = ""; CDialog::OnCancel(); } void CCharDlg::OnOK() { g_nTypeIndex = m_combo_type.GetCurSel(); CDialog::OnOK(); } bool GetSpecialChar(CWnd*pParent,CString &res) { CTemporaryResourceOverride vTemp; CCharDlg dlg(pParent); if(dlg.DoModal() != IDOK || dlg.m_character == "") return false; res=dlg.m_character; return true; }