📄 recognizer.cpp.bak
字号:
// Recognizer.cpp: implementation of the CRecognizer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Recognizer.h"
//-------------------------------------------------------------------
//Macro define
//The default value of hwxGuide
#define DEFAULT_HWXGUIDE_CHORZBOX 1
#define DEFAULT_HWXGUIDE_CVERTBOX 1
#define DEFAULT_HWXGUIDE_CXOFFSET 1
#define DEFAULT_HWXGUIDE_CYOFFSET 1
//The default value of ALC
#define DEFAULT_ALC ALC_KANJI_ALL
//--------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRecognizer::CRecognizer()
{
m_alc = NULL;
m_hrc = NULL;
m_hWndRecog = NULL;
memset(&m_hwxGuide,0,sizeof(m_hwxGuide));
}
CRecognizer::~CRecognizer()
{
}
//-----------------------------------------------------------------------
//Descriptiong:
// Initialize the recognizer
//
//Parameter:
// hWnd: [in] The handle of window to be recognized
// rcWnd: [in] The window area to be recognized
// scale: [in] The scale base of prcWnd point
//-----------------------------------------------------------------------
BOOL CRecognizer::Initialize(HWND hWnd,const RECT *prcWnd,ScaleType scale)
{
m_hWndRecog = hWnd;
m_alc = DEFAULT_ALC;
RECT rcWnd = {0};
switch(scale)
{
case SCALE_APPWND:
{
rcWnd = *prcWnd;
rcWnd.left *= 4;
rcWnd.right *= 4;
rcWnd.top *= 4;
rcWnd.bottom *= 4;
MapWindowPoints(hWnd,HWND_DESKTOP,(LPPOINT)(&rcWnd),(sizeof(RECT)/sizeof(POINT)));
break;
}
case SCALE_SCREEN:
{
rcWnd = *prcWnd;
break;
}
}
m_hwxGuide.cHorzBox = DEFAULT_HWXGUIDE_CHORZBOX;
m_hwxGuide.cVertBox = DEFAULT_HWXGUIDE_CVERTBOX;
m_hwxGuide.xOrigin = rcWnd.left;
m_hwxGuide.yOrigin = rcWnd.top;
m_hwxGuide.cxBox = rcWnd.right - rcWnd.left;
m_hwxGuide.cyBox = rcWnd.bottom - rcWnd.top;
m_hwxGuide.cxOffset = DEFAULT_HWXGUIDE_CXOFFSET;
m_hwxGuide.cyOffset = DEFAULT_HWXGUIDE_CYOFFSET;
m_hwxGuide.cxWriting = (rcWnd.right - rcWnd.left) - m_hwxGuide.cxOffset * 2;
m_hwxGuide.cyWriting = (rcWnd.bottom - rcWnd.top) - m_hwxGuide.cyOffset * 2;
m_hwxGuide.nDir = HWX_HORIZONTAL;
#ifdef RECOGNIZE_FUNCTION_FROM_DLL
HINSTANCE hInstDll;
hInstDll = LoadLibrary(RECOGNIZE_DLL_PATH);
if(hInstDll != NULL)
{
HWXCONFIG = (DLL_HWXCONFIG) GetProcAddress(hInstDll,TEXT("HwxConfig"));
HWXCREATE = (DLL_HWXCREATE) GetProcAddress(hInstDll,TEXT("HwxCreate"));
HWXSETGUIDE = (DLL_HWXSETGUIDE) GetProcAddress(hInstDll,TEXT("HwxSetGuide"));
HWXALCVALID = (DLL_HWXALCVALID) GetProcAddress(hInstDll,TEXT("HwxALCValid"));
HWXALCPRIORITY = (DLL_HWXALCPRIORITY) GetProcAddress(hInstDll,TEXT("HwxALCPriority"));
HWXSETCONTEXT = (DLL_HWXSETCONTEXT) GetProcAddress(hInstDll,TEXT("HwxSetContext"));
HWXINPUT = (DLL_HWXINPUT) GetProcAddress(hInstDll,TEXT("HwxInput"));
HWXPROCESS = (DLL_HWXPROCESS) GetProcAddress(hInstDll,TEXT("HwxProcess"));
HWXRESULTSAVAILABLE = (DLL_HWXRESULTSAVAILABLE) GetProcAddress(hInstDll,TEXT("HwxResultsAvailable"));
HWXGETRESULTS = (DLL_HWXGETRESULTS) GetProcAddress(hInstDll,TEXT("HwxGetResults"));
HWXDESTROY = (DLL_HWXDESTROY) GetProcAddress(hInstDll,TEXT("HwxDestroy"));
HWXENDINPUT = (DLL_HWXENDINPUT) GetProcAddress(hInstDll,TEXT("HwxEndInput"));
}
else
{
return FALSE;
}
#endif //RECOGNIZE_FUNCTION_FROM_DLL
return TRUE;
}
//-----------------------------------------------------------------------
//Descriptiong:
// Begin recognizing
//-----------------------------------------------------------------------
BOOL CRecognizer::BeginRecognize()
{
BOOL bRes = FALSE;
bRes = HWXCONFIG();
if(bRes == FALSE)
{
goto END;
}
m_hrc = HWXCREATE();
if(m_hrc == NULL)
{
goto END;
}
bRes = HWXSETGUIDE(m_hrc,&m_hwxGuide);
if(bRes == FALSE)
{
goto END;
}
bRes = HWXALCVALID(m_hrc,m_alc);
if(bRes == FALSE)
{
goto END;
}
bRes = TRUE;
END:
return bRes;
}
//-----------------------------------------------------------------------
//Descriptiong:
// End recognizing
//-----------------------------------------------------------------------
BOOL CRecognizer::EndRecognize()
{
BOOL bRes = FALSE;
//Destroy the recognizer
if(HWXDESTROY(m_hrc) == FALSE)
{
goto END;
}
bRes = TRUE;
END:
return bRes;
}
//-----------------------------------------------------------------------
//Descriptiong:
// Get the character
//
//Parameters:
// pWchar: [out] The character get to be stored
// iCount: [in] The number of pWchar
//
//Return Values:
// 0: Failed
// >0: The number of the characters to return
//-----------------------------------------------------------------------
int CRecognizer::GetCharacter(WCHAR *pWchar, int iCount)
{
int iGetNum = 0;
int i = 0;
HWXRESULTS *phwxResults;
//Because each HWXRESULTS after the first one could store two characters,
//so only allocate (iCount / 2 + 1)
int iNum = iCount / 2 + 1;
phwxResults = new HWXRESULTS[iNum];
memset(phwxResults,0,iNum * sizeof(HWXRESULTS));
//End the input
if(HWXENDINPUT(m_hrc) == FALSE)
{
goto END;
}
//Analyze the information
if(HWXPROCESS(m_hrc) == FALSE)
{
goto END;
}
//Get the character from recognizer
if(HWXGETRESULTS(m_hrc,iCount,0,1,phwxResults) == FALSE)
{
goto END;
}
//Set the character to the stored buffer
for(i = 0; i < iNum; i++)
{
if(i == 0)
{
if(phwxResults[i].rgChar != 0)
{
pWchar[iGetNum ++] = phwxResults[i].rgChar[0];
}
else
{
break;
}
}
else
{
//The indxBox member also store the character
if(phwxResults[i].indxBox != 0)
{
pWchar[iGetNum ++] = phwxResults[i].indxBox ;
}
else
{
break;
}
if(phwxResults[i].rgChar != 0)
{
pWchar[iGetNum ++] = phwxResults[i].rgChar[0];
}
else
{
break;
}
}
}
END:
if(phwxResults != NULL)
{
delete [] phwxResults;
}
return iGetNum;
}
//-----------------------------------------------------------------------
//Descriptiong:
// Input the stroke
//
//Parameter:
// lpPnt: [in] Pointer to the stroke POINT
// iCount: [in] The count of the lpPnt
// scale: [in] The scale base of lpPnt
//-----------------------------------------------------------------------
BOOL CRecognizer::InputStroke(POINT *lpPnt, int iCount, ScaleType scale)
{
BOOL bRes = FALSE;
int i = 0;
POINT *pt;
pt = new POINT[iCount];
if(pt == NULL)
{
goto END;
}
for(i = 0; i < iCount; i++)
{
pt[i] = lpPnt[i];
if(scale == SCALE_APPWND)
{
//Convert to the screen scale
pt[i].x *= 4;
pt[i].y *= 4;
MapWindowPoints(m_hWndRecog, HWND_DESKTOP, &pt[i], 1);
}
}
//Input stroke
bRes = HWXINPUT(m_hrc,pt,iCount,0);
if(bRes == FALSE)
{
goto END;
}
bRes = TRUE;
END:
if(pt != NULL)
{
delete [] pt;
}
return bRes;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -