【VC开源代码栏目提醒】:网学会员,鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“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("