mfc枚举所有子窗口

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();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值