基於Visual C 2010與windows SDK fo windows7開發windows7平臺的tabletp
阿新 • • 發佈:2018-12-19
基於Visual C++2010與windows SDK fo windows7開發windows7平臺的tabletpc應用(2)-漢字文件手寫軌跡輸入多語言識別
大家先看看流程與效果,然後我來講解程式碼,
1.VS2010帥氣的啟動畫面
2.VS2010的工程畫面
3。程式最終生成畫面
4.程式啟動畫面
5 程式執行畫面
6.程式列舉所有的語言識別手寫識別器
7 英文識別範例
8。韓文識別範例
9.中文識別範例
10.線條式文件
11.格子式樣文件
12.書寫嚮導模式
13.tablet pc的筆勢
核心程式碼講解如下
核心標頭檔案程式碼講解
[cpp] view plain copy print?- #pragma once
- class CAdvRecoApp :
- public CWindowImpl<CAdvRecoApp>,
- public IInkCollectorEventsImpl<CAdvRecoApp>,
- public IInkRecognitionEventsImpl<CAdvRecoApp>
- {
- public:
- // 常量
- enum {
- // 子指數
- mc_iSubmenuRecognizers = 1,
- mc_iSubmenuInputScopes = 2,
- mc_iSubmenuGuides = 3,
- mc_iSubmenuModes = 4,
- // child windows IDs
- mc_iInputWndId = 1,
- mc_iOutputWndId = 2,
- mc_iStatusWndId = 3,
- mc_iSSGestLVId = 4,
- mc_iMSGestLVId = 5,
- // 識別指南框資料
- mc_iNumRowsCols = 100,
- mc_iGuideColWidth = 100,
- mc_iGuideRowHeight = 100,
- mc_cxBoxMargin = 4,
- mc_cyBoxMargin = 4,
- // t寬度
- mc_cxGestLVWidth = 160,
- // 格子數目
- mc_cNumSSGestures = 36, // single stroke gestures
- mc_cNumMSGestures = 6, // multi-stroke gestures
- // 筆的筆記寬度
- mc_iPenWidth = 5
- };
- // COM指標,手寫引擎的物件指標
- CComPtr<IInkCollector> m_spIInkCollector;
- CComPtr<IInkRenderer> m_spIInkRenderer;
- CComPtr<IInkDisp> m_spIInkDisp;
- CComPtr<IInkStrokes> m_spIInkStrokes;
- CComPtr<IInkRecognizerContext> m_spIInkRecoContext;
- CComPtr<IInkRecognizers> m_spIInkRecognizers;
- CComPtr<IInkRecognizerGuide> m_spIInkRecoGuide;
- // 子視窗
- CInkInputWnd m_wndInput;
- CRecoOutputWnd m_wndResults;
- HWND m_hwndStatusBar;
- HWND m_hwndSSGestLV;
- HWND m_hwndMSGestLV;
- // 定義資料變數
- UINT m_nCmdRecognizer;
- UINT m_nCmdInputScope;
- UINT m_nCmdGuide;
- UINT m_nCmdMode;
- CComBSTR m_bstrCurRecoName;
- bool m_bCoerceInputScope;
- SIZE m_szGuideBox;
- bool m_bAllSSGestures;
- bool m_bAllMSGestures;
- // 建立
- staticint Run(int nCmdShow);
- //程式啟動
- CAdvRecoApp() :
- m_hwndStatusBar(NULL), m_hwndSSGestLV(NULL), m_hwndMSGestLV(NULL),
- m_bCoerceInputScope(false),
- m_nCmdGuide(0), m_nCmdInputScope(0), m_nCmdRecognizer(0), m_nCmdMode(0),
- m_bAllSSGestures(true), m_bAllMSGestures(true)
- {
- m_szGuideBox.cx = m_szGuideBox.cy = 0;
- }
- // 所有程式方法
- HMENU LoadMenu();
- bool CreateChildWindows();
- void UpdateLayout();
- void UpdateMenuRadioItems(UINT iSubMenu, UINT idCheck, UINT idUncheck);
- void UpdateInputScopeMenu();
- void UpdateStatusBar();
- bool UseRecognizer(IInkRecognizer* pIInkRecognizer);
- bool GetGestureName(InkApplicationGesture idGesture, UINT& idGestureName);
- void PresetGestures();
- DECLARE_WND_CLASS_EX(NULL, 0, -1)
- BEGIN_MSG_MAP(CAdvRecoApp)
- MESSAGE_HANDLER(WM_CREATE, OnCreate)
- MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
- MESSAGE_HANDLER(WM_SIZE, OnSize)
- COMMAND_ID_HANDLER(ID_RECOGNIZER_DEFAULT, OnRecognizer)
- COMMAND_RANGE_HANDLER(ID_RECOGNIZER_FIRST, ID_RECOGNIZER_LAST, OnRecognizer)
- COMMAND_ID_HANDLER(ID_INPUTSCOPE_COERCE, OnInputScopeCoerce)
- COMMAND_RANGE_HANDLER(ID_INPUTSCOPE_FIRST, ID_INPUTSCOPE_LAST, OnInputScope)
- COMMAND_ID_HANDLER(ID_GUIDE_NONE, OnGuide)
- COMMAND_ID_HANDLER(ID_GUIDE_LINES, OnGuide)
- COMMAND_ID_HANDLER(ID_GUIDE_BOXES, OnGuide)
- COMMAND_ID_HANDLER(ID_MODE_INK, OnMode)
- COMMAND_ID_HANDLER(ID_MODE_INK_AND_GESTURES, OnMode)
- COMMAND_ID_HANDLER(ID_MODE_GESTURES, OnMode)
- COMMAND_ID_HANDLER(ID_RECOGNIZE, OnRecognize)
- COMMAND_ID_HANDLER(ID_CLEAR, OnClear)
- COMMAND_ID_HANDLER(ID_EXIT, OnExit)
- NOTIFY_HANDLER(mc_iSSGestLVId, LVN_COLUMNCLICK, OnLVColumnClick)
- NOTIFY_HANDLER(mc_iMSGestLVId, LVN_COLUMNCLICK, OnLVColumnClick)
- NOTIFY_HANDLER(mc_iSSGestLVId, LVN_ITEMCHANGING, OnLVItemChanging)
- NOTIFY_HANDLER(mc_iMSGestLVId, LVN_ITEMCHANGING, OnLVItemChanging)
- END_MSG_MAP()
- public:
- // 訊息函式
- LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnSetFocus(UINT, WPARAM, LPARAM, BOOL& bHandled);
- LRESULT OnSize(UINT, WPARAM, LPARAM, BOOL& bHandled);
- LRESULT OnLVColumnClick(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
- LRESULT OnLVItemChanging(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
- // 命令控制代碼
- LRESULT OnRecognizer(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
- LRESULT OnInputScopeCoerce(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
- LRESULT OnInputScope(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
- LRESULT OnGuide(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
- LRESULT OnMode(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
- LRESULT OnRecognize(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
- LRESULT OnClear(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
- LRESULT OnExit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
- // 筆跡控制代碼
- HRESULT OnStroke(IInkCursor* pIInkCursor, IInkStrokeDisp* pIInkStroke,
- VARIANT_BOOL* pbCancel);
- HRESULT OnGesture(IInkCursor* pIInkCursor, IInkStrokes* pIInkStrokes,
- VARIANT vGestures, VARIANT_BOOL* pbCancel);
- //識別器控制代碼
- HRESULT OnRecognitionWithAlternates(IInkRecognitionResult* pIInkRecoResult,
- VARIANT vCustomParam,
- InkRecognitionStatus RecognitionStatus);
- };
核心原始檔的程式碼講解
[cpp] view plain copy print?- #ifndef _WIN32_WINNT
- #define _WIN32_WINNT 0x0500
- #endif
- #include <windows.h>
- #include <commctrl.h> // com指標所需標頭檔案
- #ifndef ListView_SetCheckState
- #define ListView_SetCheckState(hwndLV, i, fCheck) /
- ListView_SetItemState(hwndLV, i, INDEXTOSTATEIMAGEMASK((fCheck ? 2 : 1)), LVIS_STATEIMAGEMASK)
- #endif
- #ifndef ListView_GetCheckState
- #define ListView_GetCheckState(hwndLV, i) /
- ((((UINT)(SNDMSG((hwndLV), LVM_GETITEMSTATE, (WPARAM)(i), LVIS_STATEIMAGEMASK))) >> 12) -1)
- #endif
- #ifndef MIIM_STRING
- #define MIIM_STRING 0x00000040
- #endif
- #ifndef MIIM_FTYPE
- #define MIIM_FTYPE 0x00000100
- #endif
- // 定義陣列容納筆勢
- #define countof(array) (sizeof(array)/sizeof(array[0]))
- #include <atlbase.h> /
- CComModule _Module;
- #include <atlwin.h>
- #include <atlcom.h>
- // Tablet PC 標頭檔案
- #include <msinkaut.h>
- #include <msinkaut_i.c>
- #include <tpcerror.h>
- #include "resource.h"
- #include "EventSinks.h"
- #include "ChildWnds.h"
- #include "AdvReco.h"
- //定義初始化變數
- const LPOLESTR gc_pwsInputScopes[] = {
- L"(!IS_DEFAULT)",
- L"(!IS_URL)",
- L"(!IS_FILE_FULLFILEPATH)",
- L"(!IS_FILE_FILENAME)",
- L"(!IS_EMAIL_USERNAME)",
- L"(!IS_EMAIL_SMTPEMAILADDRESS)",
- L"(!IS_LOGINNAME)",
- L"(!IS_PERSONALNAME_FULLNAME)",
- L"(!IS_PERSONALNAME_PREFIX)",
- L"(!IS_PERSONALNAME_GIVENNAME)",
- L"(!IS_PERSONALNAME_MIDDLENAME)",
- L"(!IS_PERSONALNAME_SURNAME)",
- L"(!IS_PERSONALNAME_SUFFIX)",
- L"(!IS_ADDRESS_FULLPOSTALADDRESS)",
- L"(!IS_ADDRESS_POSTALCODE)",
- L"(!IS_ADDRESS_STREET)",
- L"(!IS_ADDRESS_STATEORPROVINCE)",
- L"(!IS_ADDRESS_CITY)",
- L"(!IS_ADDRESS_COUNTRYNAME)",
- L"(!IS_ADDRESS_COUNTRYSHORTNAME)",
- L"(!IS_CURRENCY_AMOUNTANDSYMBOL)",
- L"(!IS_CURRENCY_AMOUNT)",
- L"(!IS_DATE_FULLDATE)",
- L"(!IS_DATE_MONTH)",
- L"(!IS_DATE_DAY)",
- L"(!IS_DATE_YEAR)",
- L"(!IS_DATE_MONTHNAME)",
- L"(!IS_DATE_DAYNAME)",
- L"(!IS_DIGITS)",
- L"(!IS_NUMBER)",
- L"(!IS_ONECHAR)",
- L"(!IS_TELEPHONE_FULLTELEPHONENUMBER)",
- L"(!IS_TELEPHONE_COUNTRYCODE)",
- L"(!IS_TELEPHONE_AREACODE)",
- L"(!IS_TELEPHONE_LOCALNUMBER)",
- L"(!IS_TIME_FULLTIME)",
- L"(!IS_TIME_HOUR)",
- L"(!IS_TIME_MINORSEC)",
- L"((0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?-? ?)?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?-? ?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9)",
- L"(!IS_PERSONALNAME_FULLNAME)|((!IS_PERSONALNAME_PREFIX)? +(!IS_PERSONALNAME_GIVENNAME)+ +(!IS_PERSONALNAME_MIDDLENAME)* +(!IS_PERSONALNAME_SURNAME)+)",
- L"MN(0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)(A|B)(!IS_DIGITS)(X|Y)((0|1)*)"
- };
- constLONG gc_lMaxInputScopeMenuItemLength = 40;
- // 定義筆勢常量
- const InkApplicationGesture gc_igtSingleStrokeGestures[] = {
- IAG_Scratchout, IAG_Triangle, IAG_Square, IAG_Star, IAG_Check,
- IAG_Circle, IAG_DoubleCircle, IAG_Curlicue, IAG_DoubleCurlicue,
- IAG_SemiCircleLeft, IAG_SemiCircleRight,
- IAG_ChevronUp, IAG_ChevronDown, IAG_ChevronLeft,
- IAG_ChevronRight, IAG_Up, IAG_Down, IAG_Left, IAG_Right, IAG_UpDown, IAG_DownUp,
- IAG_LeftRight, IAG_RightLeft, IAG_UpLeftLong, IAG_UpRightLong, IAG_DownLeftLong,
- IAG_DownRightLong, IAG_UpLeft, IAG_UpRight, IAG_DownLeft, IAG_DownRight, IAG_LeftUp,
- IAG_LeftDown, IAG_RightUp, IAG_RightDown, IAG_Tap
- };
- constUINT gc_nRecommendedForMixedMode[] = {
- 0 /*Scratchout*/, 3/*Star*/, 6/*Double Circle*/,
- 7 /*Curlicue*/, 8 /*Double Curlicue*/, 25 /*Down-Left Long*/ };
- const InkApplicationGesture gc_igtMultiStrokeGestures[] = {
- IAG_ArrowUp, IAG_ArrowDown, IAG_ArrowLeft,
- IAG_ArrowRight, IAG_Exclamation, IAG_DoubleTap
- };
- const _ATL_FUNC_INFO IInkRecognitionEventsImpl<CAdvRecoApp>::mc_AtlFuncInfo =
- {CC_STDCALL, VT_EMPTY, 3, {VT_UNKNOWN, VT_VARIANT, VT_I4}};
- const _ATL_FUNC_INFO IInkCollectorEventsImpl<CAdvRecoApp>::mc_AtlFuncInfo[2] = {
- {CC_STDCALL, VT_EMPTY, 3, {VT_UNKNOWN, VT_UNKNOWN, VT_BOOL|VT_BYREF}},
- {CC_STDCALL, VT_EMPTY, 4, {VT_UNKNOWN, VT_UNKNOWN, VT_VARIANT, VT_BOOL|VT_BYREF}}
- };
- constTCHAR gc_szAppName[] = TEXT("CSDN專家尹成的程式,http://blog.csdn.net/yincheng01");
- //程式初始化視窗
- int APIENTRY WinMain(
- HINSTANCE hInstance,
- HINSTANCE/*hPrevInstance*/, // not used here
- LPSTR/*lpCmdLine*/, // not used here
- int nCmdShow
- )
- {
- int iRet = 0;
- // 初始化COM
- if (S_OK == ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))
- {
- _Module.Init(NULL, hInstance);
- // 註冊空間視窗
- INITCOMMONCONTROLSEX icc;