I've built a C# COM class that is running in a native windows app (MFC C++). The COM class is used to display video on a window handle from the main application. I'm using the .NET interop to access DirectShow in my C# app. After I render the graph I'm seeing the ActiveMovie window pop up before it is correctly positioned in the window.
Here's an example of how I'm setting up my graph. I haven't included all of the code, but I think the important part is included- rendering the graph and setting the window owner and position.
_graphBuilder = (IGraphBuilder)new FilgraphManager();
_sourceFilter = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID.AsyncReader));
hr = ((IFileSourceFilter)_sourceFilter).Load(fileName, null);
DSUtilities.ThrowExceptionForHR(hr);
hr = _graphBuilder.AddFilter(_sourceFilter, "AsyncReader");
DSUtilities.ThrowExceptionForHR(hr);
IPin output = DSUtilities.FindPinByDirection(_sourceFilter, _PinDirection.PINDIR_OUTPUT, 0);
// add some other filters
// ...
_graphBuilder.Render(output);
_videoWindow = (IVideoWindow)_graphBuilder;
_videoWindow.WindowSt开发者_StackOverflow社区yle = (int)(WindowStyle.Child | WindowStyle.ClipChildren);
_videoWindow.SetWindowPosition(_viewer.VideoRectangle.Left, _viewer.VideoRectangle.Top, _viewer.VideoRectangle.Width, _viewer.VideoRectangle.Height);
_videoWindow.Owner = viewer.CanvasHandle.ToInt32();
I believe this problem has to do with either the _graphBuilder.Render() call or setting up the window owner and window position. I've messed around with the order of the function calls and nothing seems to help. One important thing to note is that you can't grab the IVideoWindow interface until after you call Render() on the IGraphBuilder. I need to get rid of the pop-up! Has anyone else seen this issue? Or does anyone have any ideas about what's causing it? Any help will be greatly appreciated.
Thanks, Dan
This sequence of calls works for me without popping up a window:
pGraph->RenderFile(fname, NULL);
pGraph->QueryInterface( IID_IVideoWindow, (void**) &pVidWindow);
pVidWindow->put_Owner((OAHWND)hwnd);
pVidWindow->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
pVidWindow->SetWindowPosition(0, 0, grc.right, grc.bottom);
pVidWindow->put_MessageDrain( (OAHWND)hwnd );
pVidWindow->put_Visible(OATRUE);
精彩评论