我现在正在做一个视频采集的系统,基本框架是MFC下的基于对话框方式,但我发现在这种方式下kbhit()函数(判断键盘是否被打击)不能用,我想请问一下为什么?最主要是在这种方式下有什么函数或方法具有与kbhit()同样的功能?请给出函数或方法的原代码?万分火急。先谢过了。

解决方案 »

  1.   

    kbhit是DOS下的东西。
    在WINDOWS中应使用消息判断。
      

  2.   

    void CVidTestDlg::OnAcapture() 
    {
       CString Filter;
       CString Filename;
       CRect Rect;
       Filter = "Bitmap Files (*.bmp)|*.bmp|AVI Files (*.avi)|*.avi||";
       CFileDialog FileDlg(FALSE, "BMP", NULL,
                           OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
                           Filter,
                           this);
       if (FileDlg.DoModal() == IDOK)
       {
          RedrawWindow();
          Filename = FileDlg.GetPathName();
      while(!kbhit())//请问用传递消息的方式,这里应该怎么改?
      {
      Capture(m_VFWImageProc, Filename);
      }
          m_VideoDisplay.GetWindowRect(Rect);
          ScreenToClient(Rect);
          m_VFWImageProc.EnablePreviewVideo(*this, Rect.TopLeft().x,Rect.TopLeft().y);
       }
    }上面就是我的视频采集程序,请问while(!kbhit())处应怎么改?
      

  3.   

    while(!kbhit())//请问用传递消息的方式,这里应该怎么改?
      {
      Capture(m_VFWImageProc, Filename);
      }把以上代码放到CVidTestDlg的消息处理函数中去void CVidTestDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
    { Capture(m_VFWImageProc, Filename); CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
    }
      

  4.   

    实际上while(!kbhit())语句是让系统连续采集图象,直到按任一键,采集结束。
    xiaohyy,我不是很明白你给出的程序应如何用。能不能帮我修改一下。谢谢!
      

  5.   

    keybd_event
    The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function. VOID keybd_event(
      BYTE bVk,               // virtual-key code
      BYTE bScan,             // hardware scan code
      DWORD dwFlags,          // function options
      ULONG_PTR dwExtraInfo   // additional keystroke data
    );
      

  6.   

    在你的DIALOG中添加键盘按建响应函数OnKeyDown(...),然后在这个函数中终止你的视频采集就可以了!有问题就CALL ME!
      

  7.   

    我现在是这么做的:
    bool m_bKeyPressed=false;void CVidTestDlg::OnAcapture() 
    {
    // TODO: Add your command handler code here
        CString Filter;
        CString Filename;
        CRect Rect;
    Filter = "Bitmap Files (*.bmp)|*.bmp|AVI Files (*.avi)|*.avi||";
    CFileDialog FileDlg(FALSE, "BMP", NULL,
                            OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
                            Filter,
                            this);
    if (FileDlg.DoModal() == IDOK)
        {
            RedrawWindow();
    Filename = FileDlg.GetPathName();
    while(!m_bKeyPressed)
    {
    Capture(m_VFWImageProc, Filename);
    }
    m_VideoDisplay.GetWindowRect(Rect);
            ScreenToClient(Rect);
    m_VFWImageProc.EnablePreviewVideo(*this, Rect.TopLeft().x,Rect.TopLeft().y);
       }
    }BOOL CVidTestDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if(pMsg->message==WM_KEYDOWN)
    {
    m_bKeyPressed=true;
    }
    return CDialog::PreTranslateMessage(pMsg);
    }
    但不知道为什么随便怎么按键盘,消息传递函数根本不起作用,请问这是怎么回事,应该如何改?
      

  8.   

    为了调用消息传递函数,小弟定义了一个变量:
    MSG *ppp;
    可编译器总提示我未对ppp进行初始化,请问应如何对ppp进行初始化?
      

  9.   

    我测试了一下,发现下列语句
    while(!m_bKeyPressed)//此循环为连续捕捉图象
    {
    Capture(m_VFWImageProc, Filename);
    }
    将CPU完全占用了,使得键盘按键得不到响应,请那位高手能不能在我的程序的基础上帮我改改,使用线程的方式来完成上面的程序,感谢!
      

  10.   

    用GetMessage函数强行让消息响应!