MDI中,包含多个文档模板,工具栏显示在在MainFrame中,要求当一种子窗口活动时,显示自己对应的工具栏,隐藏其他子窗口对应的工具栏.

解决方案 »

  1.   

    在父窗口的PreTranslateMessage中处理WM_MOVE消息就行了。
      

  2.   

    pmwl2008:  如何处理,能详细具体点吗?
      

  3.   

    BOOL CFrameWnd::PreTranslateMessage(MSG* pMsg)
    {
    if (pMsg->hwnd == 你的子窗口句柄)
    {
    switch(pMsg->message)
    {
    case WM_MOVE:
    {
    //做你想做的事。
    }
    break;
    default:
    }
    } return CWnd::PreTranslateMessage(pMsg);
    }
      

  4.   

    BOOL CFrameWnd::PreTranslateMessage(MSG* pMsg)
    {    CWnd *pWnd;
        pWnd=this->FromHandle(pMsg->hwnd);
        if(pWnd!=NULL)
        {
    if(pWnd->IsKindOf(RUNTIME_CLASS(C3DSFrame)))
    {
                 AfxMessageBox("Is C3DSChildFrame");
        switch(pMsg->message)
        {
    case WM_MOVE:
    {
                           AfxMessageBox("C3DSChildFrame  WM_MOVE");
                           if(this->m_wndToolBar_3DSView.m_hWnd)
        {
    this->ShowControlBar(&m_wndToolBar_3DSView,TRUE,FALSE);
                           }
         break;
    }
    default:
        break;
         }
    }

    else
    {
    if(this->m_wndToolBar_3DSView.m_hWnd)
    {
          this->ShowControlBar(&m_wndToolBar_3DSView,FALSE,FALSE);
    }
     }
        }    return CMDIFrameWnd::PreTranslateMessage(pMsg);
    }/////////////////////////////
    添加上面的代码后,打开一个C3DSChildFrame子窗口(MDIChildWnd),  AfxMessageBox("Is C3DSChildFrame")会执行,AfxMessageBox("C3DSChildFrame  WM_MOVE")不会执行,工具栏没有显示出来.
      

  5.   

    我上面只是个列子.并不是一定是处理WM_MOVE消息.你的窗口活动是指什么消息就处理什么消息就可以了呀.
      

  6.   

    哦,问题后来基本解决了.重载void CMainFrame::OnIdleUpdateCmdUI(),根据子窗口的类型显示/隐藏工具栏.