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

📄 rcimeview.cpp

📁 这是一个提供给使用遥控器的嵌入式设备开发的一个中文拼音输入法
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// RCIMEView.cpp : implementation file
//

#include "stdafx.h"
#include "RCIMEView.h"
#include "winuser.h"
#include <afxwin.h>
#include "windef.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#ifdef _WIN32_WCE
#define _SETFOCUS
#else
#define _SETFOCUS SetFocus()
#endif

#define VK_0     0x30
#define VK_1     0x31
#define VK_2     0x32
#define VK_3     0x33
#define VK_4     0x34
#define VK_5     0x35
#define VK_6     0x36
#define VK_7     0x37
#define VK_8     0x38
#define VK_9     0x39
#define VK_F9			  0x78
#define VK_F10            0x79
#define VK_F11            0x7A
#define VK_F12            0x7B

/////////////////////////////////////////////////////////////////////////////
// CRCIMEView
IMPLEMENT_DYNCREATE(CRCIMEView, CView)

CRCIMEView::CRCIMEView()
{
	m_IsShowHZ=TRUE;
	m_bDrawing=FALSE;
	m_nLineWidth=1;
	m_cLineColor=RGB(0,0,0);
	m_cFillColor=RGB(0,0,255);
	m_clrdisable=RGB(225,225,225);
	m_cFocusColor=RGB(255,255,0);
	isdrawing=isdrawshengmu;
	prekeynum=VK_F9;
	m_selected=0;
	m_selectedsheng=0;
	m_selectedyun=0;
	m_selectedhanzi=0;
	m_multipages=FALSE;
	m_PageNo=1;
	m_hanzisum=0;
	m_showstrsum=0;
	for(int i=0;i<BUFFER_SIZE;i++)
		szBuf[i]=0;

	
}

CRCIMEView::~CRCIMEView()
{
//	m_pFont->DeleteObject();
}

BEGIN_MESSAGE_MAP(CRCIMEView, CView)
	//{{AFX_MSG_MAP(CRCIMEView)
	ON_WM_CREATE()
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRCIMEView drawing

void CRCIMEView::OnDraw(CDC* pDC)
{
	
	CDocument* pDoc = GetDocument();
	CRect myrc;
	CFont* oldfont;
	GetClientRect(&myrc);
	CDC mempdc;
	int hspan=(myrc.right-myrc.left )/9-2;
	BOOL bok=mempdc.CreateCompatibleDC(pDC);
	if(bok)
	{
	CBitmap membitmap;
	membitmap.CreateCompatibleBitmap(pDC,myrc.right-myrc.left,myrc.bottom-myrc.top);
	if(bok)
	{
		CDC* pMem = &mempdc;
		CBitmap* pob = pMem->SelectObject(&membitmap);
		pMem->PatBlt(0, 0, myrc.Width(), myrc.Height(), WHITENESS);
			
	DrawInterface(pMem);
	CPoint textoutpoint[36];
	WORD W;
	int nSum;
	GetTextOutPoint(textoutpoint,36);
	pMem->SetBkMode(TRANSPARENT);
	oldfont=pMem->SelectObject(m_pFontNum);
	DrawNum(pMem,textoutpoint,m_clrnum,hspan);
	pMem->SelectObject(m_pFontStr);
	switch(isdrawing)
	{
	case DRAW_SHENGMU:
			nSum=GetParent()->SendMessage(m_nCallMsgSY,(WPARAM)-1,(LPARAM)&m_shengmudesc);
			DrawShengMu(pMem,textoutpoint,m_shengmudesc,nSum);
#if defined(_WIN32_WCE) && !defined(_MIPS_)
			::TransparentImage(pDC->m_hDC,0,0, myrc.Width(), myrc.Height(),
				mempdc.m_hDC, 0, 0, myrc.Width(), myrc.Height(),
				RGB(255, 255, 255));
#else
			pDC->BitBlt(0,0,myrc.right-myrc.left,myrc.bottom-myrc.top,pMem,0,0,SRCCOPY);
		 
#endif
		 _SETFOCUS;	
		 break;
	case DRAW_YUNMU:
		 m_selectedsheng=m_selected-2;
		 nSum=GetParent()->SendMessage(m_nCallMsgSY,(WPARAM)m_selectedsheng,(LPARAM)&m_yunmudesc);
		 DrawYunMu(pMem,textoutpoint,m_yunmudesc,nSum);
	#if defined(_WIN32_WCE) && !defined(_MIPS_)
			::TransparentImage(pDC->m_hDC,0,0, myrc.Width(), myrc.Height(),
				mempdc.m_hDC, 0, 0, myrc.Width(), myrc.Height(),
				RGB(255, 255, 255));
#else
			pDC->BitBlt(0,0,myrc.right-myrc.left,myrc.bottom-myrc.top,pMem,0,0,SRCCOPY);
		 
#endif
		 _SETFOCUS;
		 break;
	case DRAW_HANZI:
		  if(!m_multipages)
		 {
		    //m_selectedyun=nYunMuIndex[m_selected-1];
			m_selectedyun=m_selected;
		    W=MAKEWORD(m_selectedsheng,m_selectedyun);
			//W=MakeWord(m_selectedsheng,m_selectedyun);
			for(int i=0;i<BUFFER_SIZE;i++)
	        	szBuf[i]=0;
			nSum=GetParent()->SendMessage(m_nCallMsgHZ,W,(LPARAM)&szBuf);
			m_hanzisum=nSum;

			if (nSum>27) m_multipages=TRUE;
		 };
		 if(m_hanzisum==0)
		 {
			m_PageNo=1;
			m_multipages=FALSE;
			isdrawing=isdrawshengmu;
			m_selectedsheng=0;
			m_selectedyun=0;
			m_hanzisum=0;
			m_showstrsum=0;
			InvalidateRect(NULL,FALSE);
			break;
		 };
		 if(m_hanzisum==1)
		 {
			m_PageNo=1;
			m_multipages=FALSE;
			isdrawing=isgottenhanzi;
			m_selectedsheng=0;
			m_selectedyun=0;
			m_showstrsum=1;
			m_selected=1;
			InvalidateRect(NULL,FALSE);
			break;
		 }
		 DrawHanZi(pMem,textoutpoint,szBuf,m_hanzisum);
#if defined(_WIN32_WCE) && !defined(_MIPS_)
			::TransparentImage(pDC->m_hDC,0,0, myrc.Width(), myrc.Height(),
				mempdc.m_hDC, 0, 0, myrc.Width(), myrc.Height(),
				RGB(255, 255, 255));
#else
			pDC->BitBlt(0,0,myrc.right-myrc.left,myrc.bottom-myrc.top,pMem,0,0,SRCCOPY);
		 
#endif
		 _SETFOCUS;
		 break;
	case GOTTEN_HANZI:
		 if(m_PageNo==1) m_selectedhanzi=m_selected;
		 else
			 m_selectedhanzi=(m_PageNo-1)*25+1+m_selected;
		 m_PageNo=1;
		 m_multipages=FALSE;
		 isdrawing=isdrawshengmu;
		 m_selectedsheng=0;
	     m_selectedyun=0;
		 m_hanzisum=0;
		 m_showstrsum=0;
	     GetParent()->PostMessage(m_nCallMsgHZ,0,szBuf[m_selectedhanzi-1]);
		 InvalidateRect(NULL,FALSE);

	};
	pMem->SelectObject(pob);
	membitmap.DeleteObject();
		 
	};
	};
	if(!bok)
	{
			
	DrawInterface(pDC);
	CPoint textoutpoint[36];
	WORD W;
	int nSum;
	GetTextOutPoint(textoutpoint,36);
	pDC->SetBkMode(TRANSPARENT);
	//pDC->SetTextColor(RGB(0,0,0));
	//pDC->SetBkColor(RGB(200,200,200));
	oldfont=pDC->SelectObject(m_pFontNum);
	DrawNum(pDC,textoutpoint,m_clrnum,hspan);
	pDC->SelectObject(m_pFontStr);
	switch(isdrawing)
	{
	case DRAW_SHENGMU:
	     nSum=GetParent()->SendMessage(m_nCallMsgSY,WPARAM(-1),(LPARAM)&m_shengmudesc);
		 DrawShengMu(pDC,textoutpoint,m_shengmudesc,nSum);
		 _SETFOCUS;	
		 break;
	case DRAW_YUNMU:
		 m_selectedsheng=m_selected-2;
		 nSum=GetParent()->SendMessage(m_nCallMsgSY,(WPARAM)m_selectedsheng,(LPARAM)&m_yunmudesc);
		 DrawYunMu(pDC,textoutpoint,m_yunmudesc,nSum);
		 _SETFOCUS;
		 break;
	case DRAW_HANZI:
		  if(!m_multipages)
		 {
		    //m_selectedyun=nYunMuIndex[m_selected-1];
			m_selectedyun=m_selected;
		    W=MAKEWORD(m_selectedsheng,m_selectedyun);
			//W=MakeWord(m_selectedsheng,m_selectedyun);
			for(int i=0;i<BUFFER_SIZE;i++)
	        	szBuf[i]=0;
			nSum=GetParent()->SendMessage(m_nCallMsgHZ,W,(LPARAM)&szBuf);
			m_hanzisum=nSum;
			if (nSum>27) m_multipages=TRUE;
		 };
		  if(m_hanzisum==0)
		 {
			m_PageNo=1;
			m_multipages=FALSE;
			isdrawing=isdrawshengmu;
			m_selectedsheng=0;
			m_selectedyun=0;
			m_hanzisum=0;
			m_showstrsum=0;
			InvalidateRect(NULL,FALSE);
			break;
		 };
		 if(m_hanzisum==1)
		 {
			m_PageNo=1;
			m_multipages=FALSE;
			isdrawing=isgottenhanzi;
			m_selectedsheng=0;
			m_selectedyun=0;
			m_showstrsum=1;
			m_selected=1;
			InvalidateRect(NULL,FALSE);
			break;
		 }
		 DrawHanZi(pDC,textoutpoint,szBuf,m_hanzisum);
		 _SETFOCUS;
		 break;
	case GOTTEN_HANZI:
		 if(m_PageNo==1) m_selectedhanzi=m_selected;
		 else
			 m_selectedhanzi=(m_PageNo-1)*25+1+m_selected;
		 m_PageNo=1;
		 m_multipages=FALSE;
		 isdrawing=isdrawshengmu;
		 m_selectedsheng=0;
	     m_selectedyun=0;
		 m_hanzisum=0;
		 m_showstrsum=0;
	     GetParent()->PostMessage(m_nCallMsgHZ,0,szBuf[m_selectedhanzi-1]);
		 InvalidateRect(NULL,FALSE);

	};
	 
	}

	
}
void CRCIMEView::DrawInterface(CDC* pDC)
{
	int i,j;
	CBrush mybrush(RGB(200,200,200));
	CBrush yellowbrush(m_cFocusColor);
	CBrush* oldbrush;
	oldbrush=pDC->SelectObject(&mybrush);
	CRect myrc;
	CRect temprect;
	GetClientRect(&myrc);
	pDC->FillRect(myrc,&mybrush);
	CPen mypen,whitepen,blackpen;
	//mypen.CreatePen(PS_SOLID,1,RGB(170,170,170));
	whitepen.CreatePen(PS_SOLID,0,RGB(240,240,240));
	blackpen.CreatePen(PS_SOLID,0,RGB(100,100,100));
	int hspan=(myrc.right-myrc.left )/9;
	int vspan=(myrc.bottom-myrc.top-m_nNumHi)/3;
	for(i=0;i<9;i++)
		for(j=0;j<4;j++)
		{
			if(j!=3)
			{
				//CBrush mybrush(m_clrBand[i]);
				DrawBtn(pDC,&mybrush,&whitepen,&blackpen,myrc.left +i*hspan,myrc.top +j*vspan,hspan,vspan);
			}
			else
			{
				//CBrush mybrush(m_clrBand[i]);
				DrawBtn(pDC,&mybrush,&whitepen,&blackpen,myrc.left +i*hspan,myrc.top +3*vspan,hspan,m_nNumHi);
			};

		}
	whitepen.DeleteObject();
	blackpen.DeleteObject();
	pDC->SelectObject(oldbrush);
	mybrush.DeleteObject();
	if(IsEnableHZ())
	{
	oldbrush=pDC->SelectObject(&yellowbrush);
	myrc.bottom-=m_nNumHi;
	switch(prekeynum)
	{
	case VK_F11:
		for(i=0;i<=8;i++)
		{
			temprect.left=myrc.left+i*hspan+1;
			temprect.right=myrc.left+(i+1)*hspan-2;
			temprect.top=myrc.top+vspan+1;
			temprect.bottom=myrc.bottom-vspan-2;
		    pDC->FillRect(temprect,&yellowbrush);
		};
		break;
	case VK_F12:
		for(i=0;i<=8;i++)
		{
			temprect.left=myrc.left+i*hspan+1;
			temprect.right=myrc.left+(i+1)*hspan-2;
			temprect.top=myrc.top+2*vspan+1;
			temprect.bottom=myrc.bottom-2;
		    pDC->FillRect(temprect,&yellowbrush);
		};
		break;
	case VK_F9:
		for(i=0;i<=8;i++)
		{
			temprect.left=myrc.left+i*hspan+1;
			temprect.right=myrc.left+(i+1)*hspan-2;
			temprect.top=myrc.top+1;
			temprect.bottom=myrc.bottom-2*vspan-2;
		    pDC->FillRect(temprect,&yellowbrush);
		};
		break;
	default:
		for(i=0;i<=8;i++)
		{
			temprect.left=myrc.left+i*hspan+1;
			temprect.right=myrc.left+(i+1)*hspan-2;
			temprect.top=myrc.top+1;
			temprect.bottom=myrc.bottom-2*vspan-2;
		    pDC->FillRect(temprect,&yellowbrush);
		};
	};
	pDC->SelectObject(oldbrush);
	yellowbrush.DeleteObject();
	};
	
		// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CRCIMEView diagnostics

void CRCIMEView::AssertValid() const
#ifdef _DEBUG
{
	CView::AssertValid();
}

void CRCIMEView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CRCIMEView message handlers

int CRCIMEView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	
	return 0;
}


BOOL CRCIMEView::MyCreate(CWnd* pParent,CRect rPos,UINT nCallMsgSY,UINT nCallMsgHZ,CFont* pFontNum,CFont* pFontStr, COLORREF clrStr, COLORREF clrNum,COLORREF clrBand[],int nNumHi)
{
	//m_fn=filename;
	//GetSYDBFileData(m_fn);
	BOOL b = CView::Create(NULL, NULL, WS_BORDER, rPos, pParent, 100);	
	ShowWindow(SW_SHOW);
	m_nCallMsgSY = nCallMsgSY;
	m_nCallMsgHZ = nCallMsgHZ;
	m_pFontNum=pFontNum;
	m_pFontStr=pFontStr;
	m_pFontStr->GetLogFont(&m_lfStr);
	m_pFontNum->GetLogFont(&m_lfNum);
	m_clrnum=clrNum;
	m_clrstr=clrStr;
	for(int i=0;i<9;i++)
		m_clrBand[i]=clrBand[i];
	m_nNumHi=nNumHi;
	return b;
}

void CRCIMEView::DrawBtn(CDC* pDC,CBrush* brush,CPen* wpen,CPen* bpen,int x,int y,int hspan,int vspan)
{
	//CBrush* oldbrush;
	//CPen* oldpen;
	pDC->SelectObject(wpen);
	pDC->MoveTo(x,y);
	pDC->LineTo(x,y+vspan-1);
	pDC->MoveTo(x,y);
	pDC->LineTo(x+hspan-1,y);
	pDC->SelectObject(bpen);
	
	pDC->MoveTo(x+hspan-1,y+vspan-1);
	pDC->LineTo(x+hspan-1,y);
	pDC->MoveTo(x+hspan-1,y+vspan-1);
	pDC->LineTo(x,y+vspan-1);
	//oldbrush=pDC->SelectObject(brush);
	CRect temprect;
	temprect.left=x+1;
	temprect.right=x+hspan-2;
	temprect.top=y+1;
	temprect.bottom=y+vspan-2;
	pDC->FillRect(temprect,brush);	
}

void CRCIMEView::GetTextOutPoint(CPoint textoutpoint[],int nSize)
{
	int i,j;
	int hei=0,nhei=0;
	int index=0;
	CRect myrc;
	GetClientRect(&myrc);	
	int hspan=(myrc.right-myrc.left )/9;
	int vspan=(myrc.bottom-myrc.top-m_nNumHi)/3;
	if((vspan-m_lfStr.lfHeight)>0)
		hei=(vspan-m_lfStr.lfHeight)/2;			
	if((m_nNumHi-m_lfNum.lfHeight)>0)
		nhei=(m_nNumHi-m_lfNum.lfHeight)/2;
	for(j=0;j<4;j++)
	    for(i=0;i<9;i++)
	{
			if(j!=3)
			{
				textoutpoint[index].x=myrc.left+i*hspan;
				textoutpoint[index++].y=myrc.top+j*vspan+hei;
			}

⌨️ 快捷键说明

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