新建一个基于对话框的工程,引用头文件<vfw.h> ,导入 vfw32.lib 库,库文件可以在vc存在路径中找到;
如:D:\Program Files\Microsoft Visual Studio\VC98\Lib\vfw32.lib
在窗体上添加四个个按钮,修改ID为IDC_VIDEO , IDC_CAPTURE , IDC_STOPVIDEO , IDC_STOPCAPTURE;
为按钮IDC_VIDEO添加代码开始浏览视频:
{
//create a window for captureWindow
CWnd *mywnd=new CWnd;
mywnd->Create(_T("STATIC"), "", WS_CHILD | WS_VISIBLE,CRect(0, 0, 400, 400), this, 1234);
mywnd->ShowWindow(SW_SHOW);
CRect rect;
mywnd->GetWindowRect(rect);
//create capture window
ghCapWnd=capCreateCaptureWindow( "My Own Capture Window",WS_CHILD | WS_VISIBLE ,0, 0, (rect.right-rect.left), (rect.bottom-rect.top), mywnd->GetSafeHwnd(), 1235);
//connect device
capDriverConnect (ghCapWnd, 0);
//get params
CAPTUREPARMS CapParms;
capCaptureGetSetup(ghCapWnd,&CapParms,sizeof (CAPTUREPARMS))
//设置桢速
CapParms.dwRequestMicroSecPerFrame=40000;
//有无时间限制
CapParms.fLimitEnabled = FALSE;
//是否捕捉音频
CapParms.fCaptureAudio = FALSE;
//MCI Device支持
CapParms.fMCIControl = FALSE;
//设置窗口,如果为false,捕捉画面在桌面上
CapParms.fYield = TRUE;
//停止捕捉键设置
CapParms.vKeyAbort = VK_ESCAPE;
CapParms.fAbortLeftMouse = FALSE;
CapParms.fAbortRightMouse = FALSE;
capCaptureSetSetup(ghCapWnd,&CapParms,sizeof (CAPTUREPARMS));
//设置预览时的比例
capPreviewScale(ghCapWnd, 1);
//设置预览时的帧频率
capPreviewRate(ghCapWnd,66);
//是否支持比例变化
capPreviewScale(ghCapWnd,FALSE);
//打开预览
capPreview(ghCapWnd, 1);
}
为IDC_CAPTURE添加代码开始捕获视频:
{
capCaptureSequence(ghCapWnd);
}
为IDC_STOPCAPTURE添加代码停止捕捉:
{
capCaptureAbort(ghCapWnd);
}
为IDC_STOPVIDEO添加代码断开连接:
{
capDriverDisconnect(ghCapWnd);
}
此程序只是简单的显示和捕捉视频, 旨在给那些像我一样搜到很多资料但又没有找到入口点的菜鸟一个入口,至于更高深的内容还有待各位大侠不吝赐教.