📄 findhzview.cpp
字号:
// findhzView.cpp : implementation of the CFindhzView class
//
#include "stdafx.h"
#include "findhz.h"
#include "findhzDoc.h"
#include "findhzView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFindhzView
IMPLEMENT_DYNCREATE(CFindhzView, CView)
BEGIN_MESSAGE_MAP(CFindhzView, CView)
//{{AFX_MSG_MAP(CFindhzView)
ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
ON_COMMAND(ID_MENUITEM32772, OnMenuitem32772)
ON_WM_KEYDOWN()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFindhzView construction/destruction
CFindhzView::CFindhzView()
{
// TODO: add construction code here
}
CFindhzView::~CFindhzView()
{
}
BOOL CFindhzView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CFindhzView drawing
void CFindhzView::OnDraw(CDC* pDC)
{
CFindhzDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CFindhzView diagnostics
#ifdef _DEBUG
void CFindhzView::AssertValid() const
{
CView::AssertValid();
}
void CFindhzView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CFindhzDoc* CFindhzView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFindhzDoc)));
return (CFindhzDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFindhzView message handlers
#include "dlgbihua.h"
#include "dlgbushou.h"
#include <io.h>
#include <imm.h>
#pragma comment(lib,"imm32.lib")
typedef struct _SBh
{
int code; //Unicode编码
int cbs; //笔画数
}SBh;
int *a=0;
SBh *b=0;
SBh *c=0;
int way=-1;
int idx=-1;
int base; //19968
int end; //40869
void CFindhzView::OnMenuitem32771()
{ //按笔画
// TODO: Add your command handler code here
CDlgBihua dlg;
WCHAR wstr[3];
char cstr[3];
int ir,i,t;
way=1;
if(0==b) InitWordBihua();
RedrawWindow();
ir=dlg.DoModal();
if(IDCANCEL==ir)
{
base=0-1;
end=20902-1;
}
else //(IDOK==ir)
{
i=0;
while(dlg.m_cbs>b[i].cbs) ++i;
base=i-1;
while(dlg.m_cbs==b[i].cbs) ++i;
end=i-1;
}
++base;
if(base>20902-1) base=20902-1;
wstr[0]=b[base].code;
wstr[1]=0;
WideCharToMultiByte(CP_ACP,0,wstr,-1,cstr,3,0,0);
t=b[base].cbs;
ShowHanzi(cstr,wstr,t);
}
void CFindhzView::InitWordBihua()
{
char cstr[3],num[10],info[80];
long filen,i,j,t,n;
BYTE *buf;
FILE *fp;
b=new SBh[20902];
VERIFY(b!=0);
fp=fopen("bhsort1.dat","rb");
filen=_filelength(_fileno(fp));
buf=new BYTE[filen];
fread(buf,1,filen,fp);
fclose(fp);
i=n=0;
while(i<filen)
{
j=0;
while(buf[i]!='\r'&&buf[i+1]!='\n')
{
info[j]=buf[i];
++j;
++i;
}
info[j]='\0';
strncpy(num,info,5);
j=atoi(num);
strncpy(cstr,info+6,2);
t=atoi(info+9);
b[n].code=j;
b[n].cbs=t;
++n;
while(('\r'==buf[i]||'\n'==buf[i])&&i<filen) ++i;
}
}
void CFindhzView::OnMenuitem32772()
{ //按部首
// TODO: Add your command handler code here
CDlgBushou dlg;
WCHAR wstr[3];
char cstr[3];
int ir,i,t;
way=2;
if(0==a) InitWordBushou();
RedrawWindow();
ir=dlg.DoModal();
if(IDCANCEL==ir||""==dlg.m_BuShou)
{
base=19968-1;
end=40869;
}
else //(IDOK==ir)
{
strcpy(cstr,dlg.m_BuShou);
MultiByteToWideChar(CP_ACP,0,cstr,3,wstr,3);
i=0;
while(i<=idx)
{
if(abs(c[i].code-wstr[0])<=1) break;
++i;
}
if(i>idx)
{
AfxMessageBox("未知的部首!!!");
base=19968-1;
end=40869;
}
else //(i<=idx)
{
base=c[i].code-1;
end=40869;
}
}
++base;
if(base>40869) base=40869;
wstr[0]=base;
wstr[1]=0;
WideCharToMultiByte(CP_ACP,0,wstr,-1,cstr,3,0,0);
t=a[wstr[0]-19968];
ShowHanzi(cstr,wstr,t);
}
void CFindhzView::InitWordBushou()
{
char cstr[3],num[10],info[80];
long filen,i,j,t,n;
BYTE *buf;
FILE *fp;
a=new int[20902];
VERIFY(a!=0);
fp=fopen("bhsort2.dat","rb");
filen=_filelength(_fileno(fp));
buf=new BYTE[filen];
fread(buf,1,filen,fp);
fclose(fp);
i=n=0;
while(i<filen)
{
j=0;
while(buf[i]!='\r'&&buf[i+1]!='\n')
{
info[j]=buf[i];
++j;
++i;
}
info[j]='\0';
strncpy(num,info,5);
j=atoi(num);
strncpy(cstr,info+6,2);
t=atoi(info+9);
++n;
a[j-19968]=t;
while(('\r'==buf[i]||'\n'==buf[i])&&i<filen) ++i;
}
c=new SBh[300];
VERIFY(c!=0);
i=j=0;
c[j].code=i+19968;
c[j].cbs=a[i];
while(i<n-1)
{
if(a[i]<=a[i+1]) ++i;
else if(1<=a[i]-a[i+1]&&a[i]-a[i+1]<=5) ++i;
else //其它情况
{
++i;
++j;
c[j].code=i+19968;
c[j].cbs=a[i];
}
}
idx=j;
}
void CFindhzView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
WCHAR wstr[3];
char cstr[3];
int t;
RedrawWindow();
if(VK_DOWN==nChar)
{
if(1==way)
{
++base;
if(base>20902-1) base=20902-1;
wstr[0]=b[base].code;
wstr[1]=0;
WideCharToMultiByte(CP_ACP,0,wstr,-1,cstr,3,0,0);
t=b[base].cbs;
}
else if(2==way)
{
++base;
if(base>40869) base=40869;
wstr[0]=base;
wstr[1]=0;
WideCharToMultiByte(CP_ACP,0,wstr,-1,cstr,3,0,0);
t=a[wstr[0]-19968];
}
ShowHanzi(cstr,wstr,t);
}
else if(VK_UP==nChar)
{
if(1==way)
{
--base;
if(base<0) base=0;
wstr[0]=b[base].code;
wstr[1]=0;
WideCharToMultiByte(CP_ACP,0,wstr,-1,cstr,3,0,0);
t=b[base].cbs;
}
else if(2==way)
{
--base;
if(base<19968) base=19968;
wstr[0]=base;
wstr[1]=0;
WideCharToMultiByte(CP_ACP,0,wstr,-1,cstr,3,0,0);
t=a[wstr[0]-19968];
}
ShowHanzi(cstr,wstr,t);
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CFindhzView::ShowHanzi(char cstr[],WCHAR wstr[],int t)
{
CClientDC cdc(this);
CFont NowFont,*pOldFont;
CBrush NowBru,*pOldBru;
LOGFONT lf;
char info[80];
sprintf(info,"笔画数:%d ",t);
cdc.TextOut(210,10,info);
sprintf(info,"Unicode编码:%d ",wstr[0]);
cdc.TextOut(210,30,info);
InitFont(&lf,-120,"宋体");
NowFont.CreateFontIndirect(&lf);
pOldFont=cdc.SelectObject(&NowFont);
NowBru.CreateSolidBrush(RGB(0xff,0xd7,0x00));
pOldBru=cdc.SelectObject(&NowBru);
cdc.SetBkMode(TRANSPARENT);
cdc.BeginPath();
cdc.TextOut(10,10,cstr);
cdc.EndPath();
cdc.StrokeAndFillPath();
DisplaySpell(&cdc,cstr);
cdc.SelectObject(pOldFont);
cdc.SelectObject(pOldBru);
}
void CFindhzView::InitFont(LOGFONT *pLF,int size,char face[])
{
ZeroMemory(pLF,sizeof(LOGFONT));
pLF->lfHeight=size;
pLF->lfWidth=0;
pLF->lfEscapement=0;
pLF->lfOrientation=0;
pLF->lfWeight=FW_NORMAL;
pLF->lfItalic=0;
pLF->lfUnderline=0;
pLF->lfStrikeOut=0;
pLF->lfCharSet=DEFAULT_CHARSET;
pLF->lfOutPrecision=OUT_DEFAULT_PRECIS;
pLF->lfClipPrecision=CLIP_DEFAULT_PRECIS;
pLF->lfQuality=DEFAULT_QUALITY;
pLF->lfPitchAndFamily=DEFAULT_PITCH;
strcpy(pLF->lfFaceName,face);
}
void CFindhzView::DisplaySpell(CDC *pDC,char cstr[])
{
UINT ListCount,ListID,ImeID,MaxKey;
char ImeName[80],Kanji[3];
BYTE buffer[80];
LRESULT lRet;
HKL list[20];
DWORD gcl;
CFont *pOldFont,font;
CBrush *pOldBru,bru;
LOGFONT lf;
Kanji[0]=cstr[0];
Kanji[1]=cstr[1];
Kanji[2]='\0';
ListCount=GetKeyboardLayoutList(20,list);
for(ListID=0;ListID<ListCount;++ListID)
{
lRet=ImmEscape(list[ListID],0,IME_ESC_IME_NAME,ImeName);
if(lRet>0)
{
if(0==strcmp(ImeName,"微软拼音输入法"))
{
ImeID=ListID;
break;
}
}
}
MaxKey=ImmEscape(list[ImeID],0,IME_ESC_MAX_KEY,0);
VERIFY(8==MaxKey);
gcl=ImmGetConversionList(list[ImeID],0,Kanji,0,0,GCL_REVERSECONVERSION);
gcl=ImmGetConversionList(list[ImeID],0,Kanji,(CANDIDATELIST*)buffer,gcl,GCL_REVERSECONVERSION);
if(gcl>0)
{
CANDIDATELIST *pList=(CANDIDATELIST*)buffer;
int start,end,i,j,k;
char result[20];
BYTE spell,pos;
RECT rect;
j=0;
start=pList->dwOffset[0];
end=start+MaxKey;
for(i=start;i<=end;++i)
if(' '==buffer[i]||'\0'==buffer[i])
{
result[j]='\0';
break;
}
else //其它情况
{
result[j]=buffer[i];
++j;
}
if(result[0])
{
spell=result[j-1]-'0';
result[j-1]='\0';
}
else return;
InitFont(&lf,-72,"Kingsoft Phonetic Plain");
font.CreateFontIndirect(&lf);
pOldFont=pDC->SelectObject(&font);
bru.CreateSolidBrush(0x87b8de);
pOldBru=pDC->SelectObject(&bru);
pos=0;
for(k=0;k<j-1;++k)
if('a'==result[k]||'e'==result[k]||
'o'==result[k]||'v'==result[k])
{
pos=k;
break;
}
else if('i'==result[k])
{
if('a'==result[k+1]||'e'==result[k+1]||
'o'==result[k+1]||'u'==result[k+1]) pos=k+1;
else pos=k;
break;
}
else if('u'==result[k])
{
if('a'==result[k+1]||'e'==result[k+1]||
'o'==result[k+1]||'i'==result[k+1]) pos=k+1;
else pos=k;
break;
}
else pos=pos;
GetClientRect(&rect);
pDC->SetBkMode(TRANSPARENT);
if('a'==result[pos]) result[pos]=128+spell;
else if('e'==result[pos]) result[pos]=132+spell;
else if('i'==result[pos]) result[pos]=136+spell;
else if('o'==result[pos]) result[pos]=140+spell;
else if('u'==result[pos]) result[pos]=144+spell;
else if('v'==result[pos]) result[pos]=148+spell;
else if('m'==result[pos]) result[pos]=152+spell;
else if('n'==result[pos]) result[pos]=156+spell;
else result[pos]=result[pos];
pDC->SetBkMode(TRANSPARENT);
pDC->BeginPath();
pDC->TextOut(10,rect.bottom/3*2,result);
pDC->EndPath();
pDC->StrokeAndFillPath();
pDC->SelectObject(pOldFont);
pDC->SelectObject(pOldBru);
}
}
void CFindhzView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
if(b) delete[]b;
if(a)
{
delete[]a;
delete[]c;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -