BOOL CALLBACK EnumChildProc( HWND hwnd, LPARAM lParam )
{
if( hwnd )
{
TCHAR ch[100];
CWnd::FromHandle( hwnd )->GetWindowText ( ch, 100 );
AfxMessageBox( ch );
}
else
return false;
}
void CEnumWindowDlg::OnBnClickedOk()
{
EnumChildWindows( this->GetSafeHwnd(), EnumChildProc, 0 );
}
/
// 测试dshow子窗口
IGraphBuilder *pGraph = NULL;
IMediaControl *pMediaControl = NULL;
IVideoWindow *pVidWin = NULL;
HWND g_hwnd;
void PlayFile(void)
{
// Create the filter graph manager.
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **)&pGraph);
pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVidWin);
// Build the graph.
pGraph->RenderFile(L"C://example.avi", NULL);
//Set the video window. //Attach the video playback window to the desired parent window. //call the IVideoWindow::put_Owner method and pass it a handle to the owner window.
pVidWin->put_Owner((OAHWND)g_hwnd);
pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
RECT grc;
GetClientRect(g_hwnd, &grc);
pVidWin->SetWindowPosition(0, 0, grc.right/2, grc.bottom/2);
// Run the graph.
pMediaControl->Run();
}
void CleanUp(void)
{ //Before the application exits, it is important that //you set the visibility of the video window to false. // Otherwise, a video image remains on the screen //and the user cannot get rid of it. Then, reset the owner to NULL; //otherwise, messages are sent to the wrong window, likely causing errors.
pVidWin->put_Visible(OAFALSE);
pVidWin->put_Owner(NULL);
pMediaControl->Release();
pVidWin->Release();
pGraph->Release();
}
void CEnumWindowDlg::OnBnClickedOk()
{
g_hwnd = this->GetSafeHwnd();
PlayFile(); // 异步播放,下边只要对应子窗口的模态对话框不都结束, 就不会cleanup
EnumChildWindows( this->GetSafeHwnd(), EnumChildProc, 0 );
CleanUp();
}