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 );
在WINDOWS中应使用消息判断。
{
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())处应怎么改?
{
Capture(m_VFWImageProc, Filename);
}把以上代码放到CVidTestDlg的消息处理函数中去void CVidTestDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{ Capture(m_VFWImageProc, Filename); CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
xiaohyy,我不是很明白你给出的程序应如何用。能不能帮我修改一下。谢谢!
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
);
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);
}
但不知道为什么随便怎么按键盘,消息传递函数根本不起作用,请问这是怎么回事,应该如何改?
MSG *ppp;
可编译器总提示我未对ppp进行初始化,请问应如何对ppp进行初始化?
while(!m_bKeyPressed)//此循环为连续捕捉图象
{
Capture(m_VFWImageProc, Filename);
}
将CPU完全占用了,使得键盘按键得不到响应,请那位高手能不能在我的程序的基础上帮我改改,使用线程的方式来完成上面的程序,感谢!