CRect rect;
CStatic* pStc;
CDC* pDC;
HDC hDC;
pStc = (CStatic*)GetDlgItem(IDC_CAM);//IDC_CAM是Picture控件的ID
//拿到控件的大小
pStc->GetClientRect(&rect);
//获取控件的句柄
pDC = pStc->GetDC();
hDC =
pDC->GetSafeHdc();
//声明IplImage指针
IplImage* pFrame =
NULL;
//获取摄像头
CvCapture* pCapture =
cvCreateCameraCapture(-1);
while(1)
{
pFrame
= cvQueryFrame(pCapture);
if(!pFrame)break;
//CvvImage.h和CvvImage.cpp在OPENCV2.2之后的版本就没了,自己去下载个就行了
CvvImage
m_Cvv;
m_Cvv.CopyOf(pFrame,pFrame->nChannels);
m_Cvv.DrawToHDC(hDC,&rect);
//等待30秒或按ESC键退出
char c =
cvWaitKey(30);
if(c==27)break;
}
//释放
cvReleaseCapture(&pCapture);
cvDestroyWindow("video");
原文:http://www.cnblogs.com/dengpeng1004/p/3539850.html