典型调用顺序

必须实现以创建墨迹识别器的方法由平板电脑平台 API 调用,而不是由启用墨迹的应用程序直接调用。

以下步骤表示实现这些方法的典型调用序列:

  1. 加载 DLL。
  2. 创建 HRECOGNIZER 句柄。
  3. 创建 HRECOCONTEXT 句柄。
  4. 为此上下文设置识别器选项和模式。
  5. 笔划将添加到墨迹数据中。
  6. 输入已结束。
  7. 墨迹被识别。
  8. 返回识别结果。
  9. HRECOCONTEXT 句柄被销毁。
  10. HRECOGNIZER 句柄被销毁。

以下代码大纲中还演示了调用顺序:

CreateRecognizer(CLSID, &hrec);
while (more pieces of ink to recognize ... )
{
  // Create a context, once per piece of ink to be recognized
  hrc = CreateContext(hrec, &hrc);

  // Functions to set up options and modes for this context
  SetGuide(hrc, pGuide, 0);
  SetFactoid(hrc, 5, PHONE); // only if in application with forms
  SetFlags(hrc, RECOFLAG_WORDMODE); // rare, only if wanting word mode, no out-of-dictionary, or single segmentation
  SetWordList(hrc, hwl);

  // Adding all the strokes in this piece of ink
  while (more strokes ... )
  {
    AddStroke(hrc, NULL, 800, pPacket, pXForm);  // one call per stroke
  }
  EndInkInput(hrc);

  // This gets the ink recognized
  Process(hrc);

  // If this is a simple application, it calls this for a simple answer
  GetBestResultString(hrc, length, buffer);

  // If this is a complex application, it calls this for a complete answer
  GetLatticePtr(hrc, &pLattice);

  // Destroy the context
  DestroyContext(hrc);
}
// Called just before the application shuts down
DestroyRecognizer(hrec);

识别器 API

识别 API 体系结构