pCde);
if (FAILED(hr))
return false;
pCde->CreateClassEnumerator(CLSID_VideoInputDeviceCategory
, &pEm, 0);
if(pEm==NULL)
return false;
CComPtr <IMoniker> pM=NULL;
ULONG cFetched;
CComPtr<IBaseFilter> pBf=NULL;
if(pEm->Next(1,&pM,&cFetched)==S_OK)
{
pM->BindToObject(0,0,IID_IBaseFilter, (void**)&pBf);
pM.Release();
}
else
{
return false;
}
//将设备添加到graph
hr = m_pGraph->AddFilter(pBf, L"Video Capture");
if (FAILED(hr))
return false;
//连接一个源插口
hr=m_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW,&MEDIATYPE_Video
,pBf,NULL,NULL);
if (FAILED(hr))
return false;
pBf.Release();
//设定视频窗口
//设定视频窗口为主窗口的一个子窗口
hr=m_pVW->put_Owner((OAHWND)hWnd);
if (FAILED(hr))
return false;
//设定窗口样式
m_pVW->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
if (FAILED(hr))
return false;
//设定窗口大小
CRect rectClient;
GetClientRect(hWnd,rectClient);
m_pVW->SetWindowPosition(0, 0, 320, 240);
//设定可视
hr=m_pVW->put_Visible(OATRUE);
if (FAILED(hr))
return false;
//将对象加入到运行对象列表中
CComPtr<IRunningObjectTable> pROT;
GetRunningObjectTable(0,&pROT);
WCHAR c[128];
wsprintfW(c, L"FilterGraph %08x pid %08x\0", (DWORD_PTR)m_pGraph.p,
GetCurrentProcessId());
hr = CreateItemMoniker(L"!",c,&pM);
if (FAILED(hr))
return false;
hr = pROT->Register(ROTFLA