这是我定义的一个类
#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);

解决方案 »

  1.   

    不好意思,回复之后,这个帖子老是停留在“回复已成功,三秒后自动跳转”,并且老是刷新郁闷
    出现的问题是:遇到问题需要关闭。我们对此引起的不便表示抱歉。
    点击调试后,指针定格到此行:
    7c72120f  c3     rec
    郁闷,看不懂,大家还是帮我看看代码写的对不对吧,我是超级菜鸟,请各位费心了
      

  2.   

    http://www.vckbase.com/document/viewdoc/?id=841
    一个CWnd的模拟
      

  3.   

    点击调试后,指针定格到此行:
    7c72120f c3 rec
    -------------------------------
    我是相当的无语。
      

  4.   

    你调试运行,看看Call Stack是到哪里? 
      

  5.   

    函数CreateMyWnd中的这句代码我屏蔽后,就不会报错了,大家帮我在看看吧
    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);
      

  6.   

    RegisterWindowClass(wc.hInstance);
    ==================
    在这个函数里将WndClassEx.hIcon = NULL;和WndClassEx.hCursor加上图标和光标看看
      

  7.   

    晕,真是相当的打击,不过各位别嫌弃我,刚入手,呵呵,是不是这有错呀?
    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( );