以下是我的代码:
HRESULT InitCaptureGraph()
{
HRESULT hr; // get whatever capture device exists
//
JIF(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGB));
CComPtr< IBaseFilter > pCap;
GetDefaultCapDevice( &pCap );
if( !pCap )
{
Msg(TEXT( "No video capture device was detected on your system.\r\n\r\n"
"This sample requires a functional video capture device, such\r\n"
"as a USB web camera." ));
return E_FAIL;
} // add the capture filter to the graph
//
hr = pGB->AddFilter( pCap, L"Cap" );
if( FAILED( hr ) )
{
Msg(TEXT( "Could not put capture device in graph" ));
return hr;
} // make a capture builder graph (for connecting help)
//
CComPtr< ICaptureGraphBuilder2 > pBuilder;
hr = pBuilder.CoCreateInstance( CLSID_CaptureGraphBuilder2 );
if( !pBuilder )
{
Msg(TEXT( "Could not create capture graph builder2" ));
return hr;
} hr = pBuilder->SetFiltergraph( pGB );
if( FAILED( hr ) )
{
Msg(TEXT( "Could not set filtergraph on graphbuilder2" ));
return hr;
} CComPtr< IBaseFilter > pMux;
CComPtr< IFileSinkFilter > pSink;
USES_CONVERSION; hr = pBuilder->RenderStream( &PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video,
pCap,
NULL,
pMux );
if( FAILED( hr ) )
{
Msg(TEXT( "Could not connect capture pin" ));
return hr;
} hr = pBuilder->RenderStream( &PIN_CATEGORY_PREVIEW,
&MEDIATYPE_Video,
pCap,
NULL,
NULL );
if( FAILED( hr ) )
{
Msg(TEXT("Could not render capture pin" ));
return hr;
}
if( hr == VFW_S_NOPREVIEWPIN )
{
// preview was faked up using the capture pin, so we can't
// turn capture on and off at will.
hr = 0;
} // find the video window and stuff it in our window
//
CComQIPtr< IVideoWindow, &IID_IVideoWindow > pWindow = pGB;
if( !pWindow )
{
Msg(TEXT("Could not get video window interface" ));
return hr;
} // set up the preview window to be in our dialog
// instead of floating popup
//
if (SUCCEEDED(pWindow->put_Owner( (OAHWND)ghApp )))
{
pWindow->put_Left( 0 );
pWindow->put_Top( 0 );
pWindow->put_Width( 320 );
pWindow->put_Height( 240 );
pWindow->put_Visible( OATRUE );
pWindow->put_WindowStyle( WS_CHILD | WS_CLIPSIBLINGS );
}
// run the graph
//
CComQIPtr< IMediaControl, &IID_IMediaControl > pControl = pGB;
hr = pControl->Run( );
if( FAILED( hr ) )
{
Msg(TEXT("Could not run graph" ));
return hr;
}
return 0;
}已经put_Owner了为什么还会浮起来呢?是不是跟owner的窗口有关系呢?我的窗口是这样生成的
ghApp = CreateWindow(CLASSNAME, APPLICATIONNAME,
WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_CLIPCHILDREN | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
DEFAULT_PLAYER_WIDTH, DEFAULT_PLAYER_HEIGHT,
0, 0, ghInst, 0);
HRESULT InitCaptureGraph()
{
HRESULT hr; // get whatever capture device exists
//
JIF(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGB));
CComPtr< IBaseFilter > pCap;
GetDefaultCapDevice( &pCap );
if( !pCap )
{
Msg(TEXT( "No video capture device was detected on your system.\r\n\r\n"
"This sample requires a functional video capture device, such\r\n"
"as a USB web camera." ));
return E_FAIL;
} // add the capture filter to the graph
//
hr = pGB->AddFilter( pCap, L"Cap" );
if( FAILED( hr ) )
{
Msg(TEXT( "Could not put capture device in graph" ));
return hr;
} // make a capture builder graph (for connecting help)
//
CComPtr< ICaptureGraphBuilder2 > pBuilder;
hr = pBuilder.CoCreateInstance( CLSID_CaptureGraphBuilder2 );
if( !pBuilder )
{
Msg(TEXT( "Could not create capture graph builder2" ));
return hr;
} hr = pBuilder->SetFiltergraph( pGB );
if( FAILED( hr ) )
{
Msg(TEXT( "Could not set filtergraph on graphbuilder2" ));
return hr;
} CComPtr< IBaseFilter > pMux;
CComPtr< IFileSinkFilter > pSink;
USES_CONVERSION; hr = pBuilder->RenderStream( &PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video,
pCap,
NULL,
pMux );
if( FAILED( hr ) )
{
Msg(TEXT( "Could not connect capture pin" ));
return hr;
} hr = pBuilder->RenderStream( &PIN_CATEGORY_PREVIEW,
&MEDIATYPE_Video,
pCap,
NULL,
NULL );
if( FAILED( hr ) )
{
Msg(TEXT("Could not render capture pin" ));
return hr;
}
if( hr == VFW_S_NOPREVIEWPIN )
{
// preview was faked up using the capture pin, so we can't
// turn capture on and off at will.
hr = 0;
} // find the video window and stuff it in our window
//
CComQIPtr< IVideoWindow, &IID_IVideoWindow > pWindow = pGB;
if( !pWindow )
{
Msg(TEXT("Could not get video window interface" ));
return hr;
} // set up the preview window to be in our dialog
// instead of floating popup
//
if (SUCCEEDED(pWindow->put_Owner( (OAHWND)ghApp )))
{
pWindow->put_Left( 0 );
pWindow->put_Top( 0 );
pWindow->put_Width( 320 );
pWindow->put_Height( 240 );
pWindow->put_Visible( OATRUE );
pWindow->put_WindowStyle( WS_CHILD | WS_CLIPSIBLINGS );
}
// run the graph
//
CComQIPtr< IMediaControl, &IID_IMediaControl > pControl = pGB;
hr = pControl->Run( );
if( FAILED( hr ) )
{
Msg(TEXT("Could not run graph" ));
return hr;
}
return 0;
}已经put_Owner了为什么还会浮起来呢?是不是跟owner的窗口有关系呢?我的窗口是这样生成的
ghApp = CreateWindow(CLASSNAME, APPLICATIONNAME,
WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_CLIPCHILDREN | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
DEFAULT_PLAYER_WIDTH, DEFAULT_PLAYER_HEIGHT,
0, 0, ghInst, 0);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货