在MFC中,用微软的SPEECH SDK开发一个语音识别加控制的程序,
那个用OnRecoEvent(WPARAM wParam, LPARAM lParam)消息函数进行语音识别之后
用mouse_event控制鼠标的时候,不能继续识别语音了,就是不能让鼠标停止移动了!
关于这个应该怎么弄啊?
附语音控制部分代码:(红色部分为鼠标控制方面的,有问题!)
void CMainDlg::OnRecoEvent(WPARAM wParam, LPARAM lParam)
{
 USES_CONVERSION;
 CSpEvent event;
 HRESULT hr = S_OK;
 if(m_SREngine.m_cpRecoContext)
 {
  while(event.GetFrom(m_SREngine.m_cpRecoContext) == S_OK)
  {
   //Get the ID
   switch(event.eEventId)
   {
   case SPEI_FALSE_RECOGNITION:
    break;
   case SPEI_HYPOTHESIS:
   case SPEI_RECOGNITION:
      {
       CComPtr <ISpRecoResult> cpResult;       CSpDynamicString dstrText;
       CString strResult;
       cpResult = event.RecoResult();
       {
        cpResult ->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &dstrText, NULL);
       }
       
       strResult = W2T(dstrText);
       //::MessageBox(NULL, strResult, "teXT", MB_OK);
       if(strResult == CString("关闭"))
       {
        OnOK();
       }
       else if(strResult == CString("向右") )
       {
        while(1)
         {
        mouse_event(MOUSEEVENTFMOVE,1,0,0,0);
        Sleep(100);
         if(strResult == CString("停止") ) 
            {break;}
          else continue;
          }
       }
       else if(strResult == CString("电脑") )
       {
        ::MessageBox(NULL, "computer", "识别结果", MB_OK);
       }
       else if(strResult == CString("计算器") )
       {
        ShellExecute(NULL,"open","calc.exe",NULL,NULL,SW_SHOWNORMAL);
       }
      cpResult.Release();
      }
    break;
   default:
    break;
   }
  }
 }

解决方案 »

  1.   

    mouse_event(MOUSEEVENTFMOVE,1,0,0,0); 
    这里面又是怎么处理的呢?
      

  2.   


    mouse_event是系统自带的WINAPI吧,具体原理不知道哦!
    还有程序那个参数打错了,应该是MOUSEEVENTF_MOVE!
      

  3.   

    都和你说原因了自己改一下不就成了  else if(strResult == CString("向右") ) 
          { 
            while(1) 
            { 
            mouse_event(MOUSEEVENTFMOVE,1,0,0,0); 
            Sleep(100); 在这里插入重新检测语音的
       CComPtr <ISpRecoResult> cpResult;       CSpDynamicString dstrText; 
          CString strResult; 
          cpResult = event.RecoResult(); 
          { 
            cpResult ->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &dstrText, NULL); 
          } 
          
          strResult = W2T(dstrText); 

            if(strResult == CString("停止") ) 
                {break;} 
              else continue; 
              }      } 
      

  4.   

    去掉while循环 使用TRACE把所有接受到的消息显示出来看看是否接收命令正常
    while循环会导致其他消息阻塞
    建议 启动一个定时器 使用定时器消息来移动鼠标 很好的非阻塞操作方式