VC学习笔记:
首先在工程中加入vfw32.lib,然后新建一对话框avicap.dlg,在建一显示视频用的对话框avi.dlg在avicap.cpp中加入vfw.h,新建四个按钮video,stopvideo,capture,stopcapture.
添加private:HWND ghCapWnd;CDialog* window;
void
AVICAP::OnVideo()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
// TODO: Add your control notification handler code here
//create a window for captureWindow
window=new CDialog;
window->Create(IDD_AVI);
//create capture window
ghCapWnd=capCreateCaptureWindow("My Own Capture Window",WS_CHILD|WS_VISIBLE,0,0,400,400,window- >GetSafeHwnd(),1235);
//connect device
capDriverConnect(ghCapWnd,0);
//get params
CAPTUREPARMS CapParms;
capCaptureGetSetup(ghCapWnd,&CapParms,sizeof(CAPTUREPARMS));
//设置桢速
CapParms.dwRequestMicroSecPerFrame=50000;
//有无时间限制
CapParms.fLimitEnabled=false;
//是否捕捉音频
CapParms.fCaptureAudio=false;
//MCI Device支持
CapParms.fMCIControl=false;
//设置窗口,如果为false,捕捉画面在桌面上
CapParms.fYield=true;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//停止捕捉键设置
CapParms.vKeyAbort=VK_ESCAPE;
CapParms.fAbortLeftMouse=false;
CapParms.fAbortRightMouse=false;
capCaptureSetSetup(ghCapWnd,&CapParms,sizeof(CAPTUREPARMS));
//设置预览时的比例
capPreviewScale(ghCapWnd,1);
//设置预览时的帧频率
capPreviewRate(ghCapWnd,66);
//是否支持比例变化
capPreviewScale(ghCapWnd,false);
//获得捕捉窗口状态
CAPSTATUS CapStatus;
capGetStatus(ghCapWnd,&CapStatus,sizeof(CapStatus));
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//设置窗口大小
CRect clientRect;
ClientToScreen(clientRect);
window->SetWindowPos(window,0,0CapStatus.uiImageWidth,CapStatus.uiImageHeight+30, //+30标题高
SWP_NOZORDER|SWP_NOMOVE);
//打开窗口
window->ShowWindow(SW_SHOW);
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//打开预览
capPreview(ghCapWnd,1);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
void
AVICAP::OnStopvideo()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
// TODO: Add your control notification handler code here
capDriverDisconnect(ghCapWnd);
}
void
AVICAP::OnCapture()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
// TODO: Add your control notification handler code here
char szCaptureFile[] = "D:/MYCAP.AVI";
capFileSetCaptureFile(ghCapWnd,szCaptureFile);//指定捕获文件名
capFileAlloc(ghCapWnd,(1024L * 1024L * 5)); //为捕获文件分配存储空间
capCaptureSequence(ghCapWnd);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
void
AVICAP::OnStopcapture()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
// TODO: Add your control notification handler code here
capCaptureAbort(ghCapWnd);
}