一些特殊字符的输入,在office软件中有特殊字符对话框:图
在搜狗输入法中输入特殊字符:图
这些特殊字符的开发都可以使用vc+添加控件来插入那些特殊字符。
let'start.
使用VC+从 CStatic 派生一个新的类,我命名为 CStcImageFont,头文件如下.
#pragma once// CStcImageFontclass CStcImageFont : public CStatic{ DECLARE_DYNAMIC(CStcImageFont)public: CStcImageFont(); virtual ~CStcImageFont();protected: DECLARE_MESSAGE_MAP()public: afx_msg void OnPaint();private: CDC *m_dcFont ; CBitmap *m_bmFont ; int m_iRowX ; int m_iRowY ; int m_iCurPos ; //垂直滚动条 CScrollBar* m_pScrollBar; CStringList m_strList ; CRect m_rClient ; CString m_strSelText ; double m_dXSpace ; double m_dYSpace ;public: void SetRowXY(int iRowX , int iRowY ) ; int GetRowX( void ) ; int GetRowY( void ) ; void SetCurPos(int iPos ) ; int GetCurPos(void ) ; void Init() ; CString GetSelText(void) ; afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); afx_msg UINT OnNcHitTest(CPoint point); };
实现文件如下 CPP
// StcImageFont.cpp : 实现文件 // #include "stdafx.h" #include "TestImageSymbol.h" #include "StcImageFont.h" #include ".stcimagefont.h"// CStcImageFont IMPLEMENT_DYNAMIC(CStcImageFont, CStatic) CStcImageFont::CStcImageFont(){ m_iRowX = 10 ; m_iRowY = 10 ; m_pScrollBar = NULL ; m_dcFont = NULL ; m_bmFont = NULL ; m_iCurPos = 0 ; m_strSelText.Empty() ; } CStcImageFont::~CStcImageFont(){ if ( m_pScrollBar != NULL ) { delete m_pScrollBar ; } if ( m_dcFont != NULL ) { delete m_dcFont ; } if ( m_bmFont!= NULL ) { delete m_bmFont ; } }void CStcImageFont::Init() { unsigned char ss[3]; CString TempStr; for(int i = 161; i <= 254; i++) { for(int j = 161; j <= 254; j++) { ss[0] = i; ss[1] = j; ss[2] = 0; TempStr.Format("%s",ss) ; //滤掉无法显示的部分 if( TempStr.IsEmpty() || TempStr == " " || TempStr == " " ) continue; if( i == 162 && j >= 171 && j <= 176) continue; if( i == 162 && j >= 227 && j <= 228) continue; if( i == 162 && j >= 239 && j <= 240) continue; if( i == 162 && j >= 253 && j <= 254) continue; if( i == 164 && j >= 244 && j <= 254) continue; if( i == 165 && j >= 247 && j <= 254) continue; if( i == 166 && j >= 185 && j <= 254) continue; if( i == 167 && j >= 194 && j <= 254) continue; if( i == 168 && j >= 193 && j <= 196) continue; if( i == 168 && j >= 234 && j <= 254) continue; if( i == 169 && j >= 161 && j <= 163) continue; if( i == 169 && j >= 240 && j <= 254) continue; if( i > 169 && i < 176 ) continue; if( i >= 248 ) continue; m_strList.AddTail(TempStr) ; } } if(m_pScrollBar==NULL) { m_pScrollBar=new CScrollBar(); } RECT rc; GetClientRect(&rc); m_rClient.CopyRect(&rc) ; rc.left=rc.right-18; m_pScrollBar->Create(SBS_VERT|WS_VISIBLE|WS_CHILD,rc,this,1); SCROLLINFO si; si.cbSize=sizeof(SCROLLINFO); si.fMask=SIF_POS|SIF_RANGE|SIF_TRACKPOS; si.nMax=m_strList.GetCount()/(m_iRowX*m_iRowY ) ; si.nMin=0; si.nPos=0; si.nTrackPos=0; si.nPage=0; m_pScrollBar->SetScrollInfo(&si); m_dXSpace =(double)( (double)(m_rClient.Width() - 18 ) / (double)m_iRowX ) ; m_dYSpace =(double)( (double)m_rClient.Height() / (double)m_iRowY );
CPaintDC dc( this ); m_dcFont = new CDC() ; m_bmFont = new CBitmap() ; m_bmFont->CreateCompatibleBitmap(&dc,m_rClient.Width() - 18 , m_rClient.Height() ) ; m_dcFont->CreateCompatibleDC(&dc) ; m_dcFont->SelectObject(m_bmFont) ; InvalidateRect(&m_rClient); } BEGIN_MESSAGE_MAP(CStcImageFont, CStatic) ON_WM_PAINT() ON_WM_CREATE() ON_WM_VSCROLL() ON_WM_LBUTTONDBLCLK() ON_WM_NCHITTEST() END_MESSAGE_MAP() // CStcImageFont 消息处理程序 void CStcImageFont::OnPaint() { CPaintDC dc( this ); // device context for painting CPen pen(PS_SOLID,1,RGB(0,0,0)) ; CPen *pOldPen = m_dcFont->SelectObject(&pen) ; // 绘制字体 m_dcFont->FillSolidRect(0,0,m_rClient.Width()-18 , m_rClient.Height() , RGB(255,255,255)) ; int i , j ; for ( i = 0 ; i <= m_iRowX ; i++ ) { m_dcFont->MoveTo(i*m_dXSpace , 0 ) ; m_dcFont->LineTo(i*m_dXSpace ,m_rClient.Height() ) ; } for ( j = 0 ; j < m_iRowY ; j++ ) { m_dcFont->MoveTo(0 , j*m_dYSpace) ; m_dcFont->LineTo(m_rClient.Width()-18 ,j*m_dYSpace ) ; } m_dcFont->SelectObject(pOldPen) ; for ( j = 0 ; j < m_iRowY ; j++ ) { for ( i = 0 ; i < m_iRowX ; i++ ) { RECT rc ; rc.left = m_rClient.left + m_dXSpace * i ; rc.top = m_rClient.top + m_dYSpace * j ; rc.right = rc.left + m_dXSpace ; rc.bottom = rc.top + m_dYSpace ; POSITION pos = m_strList.FindIndex(m_iCurPos*m_iRowX * m_iRowY + j*m_iRowX + i ) ; if ( pos != NULL ) { m_dcFont->DrawText(m_strList.GetAt(pos) , &rc , DT_CENTER |DT_VCENTER | DT_SINGLELINE ) ; } } } dc.BitBlt(m_rClient.left,m_rClient.top ,m_rClient.Width()-18 ,m_rClient.Height() ,m_dcFont,0,0,SRCCOPY ) ; } int CStcImageFont::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CStatic::OnCreate(lpCreateStruct) == -1) return -1; // TODO: 在此添加您专用的创建代码 return 0; } void CStcImageFont::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: 在此添加消息处理程序代码和 / 或调用默认值 int pos=m_pScrollBar->GetScrollPos(); switch (nSBCode) { case SB_LINEDOWN : pos+=1; break ; case SB_LINEUP : pos-=1; break ; case SB_PAGEUP: pos -= 1 ; break ; case SB_PAGEDOWN: pos += 1 ; break ; case SB_THUMBTRACK : pos=nPos; break ; default : break ; } m_pScrollBar->SetScrollPos(pos); m_iCurPos=m_pScrollBar->GetScrollPos(); InvalidateRect(&m_rClient); CStatic::OnVScroll(nSBCode, nPos, pScrollBar); } void CStcImageFont::OnLButtonDblClk(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和 / 或调用默认值 int i , j ; int xIndex =-1 ; int yIndex =-1 ; for ( j = 0 ; j < m_iRowY ; j++ ) { for ( i = 0 ; i < m_iRowX ; i++ ) { RECT rc ; rc.left = m_rClient.left + m_dXSpace * i ; rc.top = m_rClient.top + m_dYSpace * j ; rc.right = rc.left + m_dXSpace ; rc.bottom = rc.top + m_dYSpace ; if ( ::PtInRect(&rc,point) ) { xIndex = i ; yIndex = j ; } } if ( xIndex != -1 && yIndex !=-1 ) break ; } POSITION pos = m_strList.FindIndex(m_iCurPos*m_iRowX * m_iRowY + yIndex*m_iRowX + xIndex ) ; if ( pos != NULL ) { m_strSelText = m_strList.GetAt(pos) ; } CStatic::OnLButtonDblClk(nFlags, point); } CString CStcImageFont::GetSelText() { return m_strSelText ; } UINT CStcImageFont::OnNcHitTest(CPoint point) { // TODO: 在此添加消息处理程序代码和 / 或调用默认值 return HTCLIENT ; }two,使用这个类,建立一个对话框类,在上面放一个 CSatic 控件.增加一个控件变量,CStcImageFont m_stcImageFont;编译图:
其它特殊字符的添加,按代码改吧。
adiOS
end