这是我定义的一个类
#include "stdafx.h"
#include "sbsburn.h"
#include "Recognition.h"
#include "msinkaut.h"
#include "msinkaut_i.c"
#include "resource.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifIInkCollector * g_pIInkCollector = NULL;
IInkDisp * g_pIInkDisp = NULL;
IInkRecognizerContext * g_pIInkRecoContext = NULL;const TCHAR* gc_szAppName = TEXT("Basic Recognition");
/////////////////////////////////////////////////////////////////////////////
// RecognitionRecognition::Recognition()
{
}Recognition::~Recognition()
{
}BOOL RegisterWindowClass(HINSTANCE hInstance)
{
WNDCLASSEX WndClassEx; WndClassEx.cbSize = sizeof(WndClassEx);
WndClassEx.style = CS_HREDRAW | CS_VREDRAW;
WndClassEx.lpfnWndProc = 0;
WndClassEx.cbClsExtra = 0;
WndClassEx.cbWndExtra = 0;
WndClassEx.hInstance = hInstance;
WndClassEx.hIcon = NULL;
WndClassEx.hIconSm = NULL;
WndClassEx.hCursor = NULL;
WndClassEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClassEx.lpszMenuName = NULL;
WndClassEx.lpszClassName = gc_szAppName; if (!RegisterClassEx(&WndClassEx))
{
MessageBox(NULL, TEXT("Failed to register window class!"),
gc_szAppName, MB_ICONERROR);
return false;
} return true;
}void Recognition::CreateMyWnd(LPCTSTR pTitle,RECT &rect)
{ //HWND s_wndPump = NULL;
HINSTANCE hInstance;
//hInstance=((LPCREATESTRUCT)lParam)->hInstance;
hInstance= AfxGetInstanceHandle( ); WNDCLASS wc;
wc.style = 0;
wc.lpfnWndProc = NULL;
wc.cbClsExtra = wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = _T("Test_Window");
RegisterWindowClass(wc.hInstance);
HWND hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, gc_szAppName, gc_szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
Create(hWnd);
//return S_OK;
}
int Recognition::Create(HWND hwnd)
{
HRESULT hr;
// Create a recognition context that uses the default recognizer.
// The single context will be used for all the recognition.
hr = CoCreateInstance(CLSID_InkRecognizerContext,
NULL, CLSCTX_INPROC_SERVER,
IID_IInkRecognizerContext,
(void **) &g_pIInkRecoContext);
if (FAILED(hr))
return -1;
// Create the InkCollector object.
hr = CoCreateInstance(CLSID_InkCollector,
NULL, CLSCTX_INPROC_SERVER,
IID_IInkCollector,
(void **) &g_pIInkCollector);
if (FAILED(hr))
return -1; // Get a pointer to the Ink object
hr = g_pIInkCollector->get_Ink(&g_pIInkDisp);
if (FAILED(hr))
return -1; // Tell InkCollector the window to collect ink in
hr = g_pIInkCollector->put_hWnd((long)hwnd);
if (FAILED(hr))
return -1; // Enable ink input in the window
hr = g_pIInkCollector->put_Enabled(VARIANT_TRUE);
if (FAILED(hr))
return -1;
}void Recognition::CRecognize(HWND hwnd)
{
// change cursor to the system's Hourglass
HCURSOR hCursor = ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
// Get a pointer to the ink stroke collection
// This collection is a snapshot of the entire ink object
IInkStrokes* pIInkStrokes = NULL;
HRESULT hr = g_pIInkDisp->get_Strokes(&pIInkStrokes);
if (SUCCEEDED(hr))
{
// Pass the stroke collection to the recognition context
hr = g_pIInkRecoContext->putref_Strokes(pIInkStrokes);
if (SUCCEEDED(hr))
{
// Recognize
IInkRecognitionResult* pIInkRecoResult = NULL;
InkRecognitionStatus RecognitionStatus;
hr = g_pIInkRecoContext->Recognize(&RecognitionStatus, &pIInkRecoResult);
if (SUCCEEDED(hr) && (pIInkRecoResult!= NULL))
{
// Get the best result of the recognition
BSTR bstrBestResult = NULL;
hr = pIInkRecoResult->get_TopString(&bstrBestResult);
pIInkRecoResult->Release();
pIInkRecoResult = NULL; // Show the result string
if (SUCCEEDED(hr) && bstrBestResult)
{
MessageBoxW(hwnd, bstrBestResult,
L"Recognition Results", MB_OK);
SysFreeString(bstrBestResult);
}
}
// Reset the recognition context
g_pIInkRecoContext->putref_Strokes(NULL);
}
pIInkStrokes->Release();
}
// restore the cursor
::SetCursor(hCursor);
}
void Recognition::CleanUp() // Release all objects
{
if (g_pIInkRecoContext != NULL)
{
g_pIInkRecoContext->Release();
g_pIInkRecoContext = NULL;
}
if (g_pIInkDisp != NULL)
{
g_pIInkDisp->Release();
g_pIInkDisp = NULL;
} if (g_pIInkCollector != NULL)
{
g_pIInkCollector->Release();
g_pIInkCollector = NULL;
}
}
BEGIN_MESSAGE_MAP(Recognition, CWnd)
//{{AFX_MSG_MAP(Recognition)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Recognition message handlers以下是我在自己的程序里调用他,老是报错,请各位指点
bWnd = new Recognition;
CRect rect1(0, 0, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CXFULLSCREEN));
bWnd->CreateMyWnd("Hand", rect1);
bWnd->ShowWindow(SW_SHOW);
bWnd->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
#include "stdafx.h"
#include "sbsburn.h"
#include "Recognition.h"
#include "msinkaut.h"
#include "msinkaut_i.c"
#include "resource.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifIInkCollector * g_pIInkCollector = NULL;
IInkDisp * g_pIInkDisp = NULL;
IInkRecognizerContext * g_pIInkRecoContext = NULL;const TCHAR* gc_szAppName = TEXT("Basic Recognition");
/////////////////////////////////////////////////////////////////////////////
// RecognitionRecognition::Recognition()
{
}Recognition::~Recognition()
{
}BOOL RegisterWindowClass(HINSTANCE hInstance)
{
WNDCLASSEX WndClassEx; WndClassEx.cbSize = sizeof(WndClassEx);
WndClassEx.style = CS_HREDRAW | CS_VREDRAW;
WndClassEx.lpfnWndProc = 0;
WndClassEx.cbClsExtra = 0;
WndClassEx.cbWndExtra = 0;
WndClassEx.hInstance = hInstance;
WndClassEx.hIcon = NULL;
WndClassEx.hIconSm = NULL;
WndClassEx.hCursor = NULL;
WndClassEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClassEx.lpszMenuName = NULL;
WndClassEx.lpszClassName = gc_szAppName; if (!RegisterClassEx(&WndClassEx))
{
MessageBox(NULL, TEXT("Failed to register window class!"),
gc_szAppName, MB_ICONERROR);
return false;
} return true;
}void Recognition::CreateMyWnd(LPCTSTR pTitle,RECT &rect)
{ //HWND s_wndPump = NULL;
HINSTANCE hInstance;
//hInstance=((LPCREATESTRUCT)lParam)->hInstance;
hInstance= AfxGetInstanceHandle( ); WNDCLASS wc;
wc.style = 0;
wc.lpfnWndProc = NULL;
wc.cbClsExtra = wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = _T("Test_Window");
RegisterWindowClass(wc.hInstance);
HWND hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, gc_szAppName, gc_szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
Create(hWnd);
//return S_OK;
}
int Recognition::Create(HWND hwnd)
{
HRESULT hr;
// Create a recognition context that uses the default recognizer.
// The single context will be used for all the recognition.
hr = CoCreateInstance(CLSID_InkRecognizerContext,
NULL, CLSCTX_INPROC_SERVER,
IID_IInkRecognizerContext,
(void **) &g_pIInkRecoContext);
if (FAILED(hr))
return -1;
// Create the InkCollector object.
hr = CoCreateInstance(CLSID_InkCollector,
NULL, CLSCTX_INPROC_SERVER,
IID_IInkCollector,
(void **) &g_pIInkCollector);
if (FAILED(hr))
return -1; // Get a pointer to the Ink object
hr = g_pIInkCollector->get_Ink(&g_pIInkDisp);
if (FAILED(hr))
return -1; // Tell InkCollector the window to collect ink in
hr = g_pIInkCollector->put_hWnd((long)hwnd);
if (FAILED(hr))
return -1; // Enable ink input in the window
hr = g_pIInkCollector->put_Enabled(VARIANT_TRUE);
if (FAILED(hr))
return -1;
}void Recognition::CRecognize(HWND hwnd)
{
// change cursor to the system's Hourglass
HCURSOR hCursor = ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
// Get a pointer to the ink stroke collection
// This collection is a snapshot of the entire ink object
IInkStrokes* pIInkStrokes = NULL;
HRESULT hr = g_pIInkDisp->get_Strokes(&pIInkStrokes);
if (SUCCEEDED(hr))
{
// Pass the stroke collection to the recognition context
hr = g_pIInkRecoContext->putref_Strokes(pIInkStrokes);
if (SUCCEEDED(hr))
{
// Recognize
IInkRecognitionResult* pIInkRecoResult = NULL;
InkRecognitionStatus RecognitionStatus;
hr = g_pIInkRecoContext->Recognize(&RecognitionStatus, &pIInkRecoResult);
if (SUCCEEDED(hr) && (pIInkRecoResult!= NULL))
{
// Get the best result of the recognition
BSTR bstrBestResult = NULL;
hr = pIInkRecoResult->get_TopString(&bstrBestResult);
pIInkRecoResult->Release();
pIInkRecoResult = NULL; // Show the result string
if (SUCCEEDED(hr) && bstrBestResult)
{
MessageBoxW(hwnd, bstrBestResult,
L"Recognition Results", MB_OK);
SysFreeString(bstrBestResult);
}
}
// Reset the recognition context
g_pIInkRecoContext->putref_Strokes(NULL);
}
pIInkStrokes->Release();
}
// restore the cursor
::SetCursor(hCursor);
}
void Recognition::CleanUp() // Release all objects
{
if (g_pIInkRecoContext != NULL)
{
g_pIInkRecoContext->Release();
g_pIInkRecoContext = NULL;
}
if (g_pIInkDisp != NULL)
{
g_pIInkDisp->Release();
g_pIInkDisp = NULL;
} if (g_pIInkCollector != NULL)
{
g_pIInkCollector->Release();
g_pIInkCollector = NULL;
}
}
BEGIN_MESSAGE_MAP(Recognition, CWnd)
//{{AFX_MSG_MAP(Recognition)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Recognition message handlers以下是我在自己的程序里调用他,老是报错,请各位指点
bWnd = new Recognition;
CRect rect1(0, 0, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CXFULLSCREEN));
bWnd->CreateMyWnd("Hand", rect1);
bWnd->ShowWindow(SW_SHOW);
bWnd->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
解决方案 »
- Clistctrl::InsertItem没有任何响应,没有任何返回值,卡死!!
- dll代码编译后无dll产生
- 如何在远程计算机未登录的情况下使用服务程序关机?(100分)
- 关于用CFile替代CFileDialog读取图象,请教??
- SOCKET问题....彻底郁闷了,大哥们帮忙看下...
- 恕小生狂妄(关于WIN2K源代码)
- 申请这个版面的版主
- 问一下,学过C++的学VC,应该先学WIN32 API还是MFC呢?!?!
- 为什么我安装SCO UNIX时,系统不认我的光驱?
- 关于List Box控件的一个小问题,望大家帮帮忙!!!
- 菜单--“最近打开文件”的全路径显示问题
- TCP WSASend发送成功 完成端口没返回结果
出现的问题是:遇到问题需要关闭。我们对此引起的不便表示抱歉。
点击调试后,指针定格到此行:
7c72120f c3 rec
郁闷,看不懂,大家还是帮我看看代码写的对不对吧,我是超级菜鸟,请各位费心了
一个CWnd的模拟
7c72120f c3 rec
-------------------------------
我是相当的无语。
HWND hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, gc_szAppName, gc_szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
Create(hWnd);
==================
在这个函数里将WndClassEx.hIcon = NULL;和WndClassEx.hCursor加上图标和光标看看
hInstance= AfxGetInstanceHandle( );
RegisterWindowClass(wc.hInstance);
HWND hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, gc_szAppName, gc_szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);这段代码的第一行:hInstance= AfxGetInstanceHandle( );