求教:控制摄像头
将摄像头截获的图像通过回调函数传给另一个程序(客户端),
为什么主程序的窗口被挡住,客户端的图像就不变了?
回调函数是在什么情况下得到图像的?
源代码:
void CCaptureServerDlg::OnBnClickedOk()
{//...
DWORD nID = m_dwSelected;
/* -- Create the capture window if we haven't done do. -- */
if (m_theVideoCapWnd.m_hWnd == NULL) {
m_theVideoCapWnd.CreateCaptureWindow(CString(""), WS_BORDER | WS_CHILD | WS_VISIBLE, CRect(38, 0, 124, 0), this, 0);
if (m_theVideoCapWnd.m_hWnd == NULL) {
MessageBox("Error: Can not Create Capture Window");
return;
}
}
/* -- Attempt to connect to driver. -- */
if (m_theVideoCapWnd.DriverConnect(nID) == FALSE) {
MessageBox("Error: Can not Connect to Driver");
return;
}
m_bConnected = TRUE;
/* -- Retrieve device parameters. -- */
CAPTUREPARMS capParms;
if (m_theVideoCapWnd.CaptureGetSetup(&capParms, sizeof(CAPTUREPARMS)) == FALSE) {
MessageBox("Error: Can not get setup parameter");
return;
}
/* -- Want separate thread. -- */
capParms.fYield = TRUE;
/* -- Do not abort when left mouse button is clicked. -- */
capParms.fAbortLeftMouse = FALSE;
/* -- Do not abort when right mouse button is clicked. -- */
capParms.fAbortRightMouse = FALSE;
/* -- Update device parameters. -- */
if (m_theVideoCapWnd.CaptureSetSetup(&capParms, sizeof(CAPTUREPARMS)) == FALSE) {
MessageBox("Error: Can not Set setup parameter");
return;
}
/* -- Get current state of capture window. -- */
if (m_theVideoCapWnd.GetStatus(&m_theCapStatus, sizeof(CAPSTATUS)) == FALSE) {
MessageBox("Error: Can not Get Status parameter");
return;
}
m_theVideoCapWnd.SetWindowPos(NULL, 0, 0, m_theCapStatus.uiImageWidth, m_theCapStatus.uiImageHeight, SWP_NOMOVE | SWP_NOZORDER);
/* -- Set preview rate. -- */
if (m_theVideoCapWnd.PreviewRate(33) == FALSE) {
MessageBox("Error: Can not Set Preview Rate");
return;
}
/* -- Turn on scaling. -- */
if (m_theVideoCapWnd.PreviewScale(TRUE) == FALSE) {
MessageBox("Error: Can not Turn on Scale");
return;
}
/* -- Start preview. -- */
if (m_theVideoCapWnd.Preview(TRUE) == FALSE) {
MessageBox("Error: Can not Start Preview");
return;
}
...
}
void CCaptureServerDlg::OnAccept()
{
//...
m_theVideoCapWnd.SetCallbackOnFrame(CCaptureServerDlg::FrameCallbackProc);
//...
}
控制摄像头的类是在CodeProject上面找到的,跟用API没什么大分别