我在程序中定义了CGraphView和CTextView两个视图,同时
pDocTemplate = new CMultiDocTemplate(
IDR_GRAPHTYPE,
RUNTIME_CLASS(CGraphDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CGraphView));
AddDocTemplate(pDocTemplate); pDocTemplate = new CMultiDocTemplate(
IDR_GRAPHTYPE,
RUNTIME_CLASS(CGraphDoc),
RUNTIME_CLASS(CMDIChildWnd), 
RUNTIME_CLASS(CSingleTextView));
AddDocTemplate(pDocTemplate);
然后定义了一个菜单NewWindowSingle,类似于New Window的功能,主要新建一个CTextView视图
我想问一下如何在新建CTextView时候,将开始打开的视图关闭?请各位高人指点不胜感激。

解决方案 »

  1.   

    FromHandle(CMDIFrameWnd::m_hWndMDIClient)得到第一个mdi子窗口
      

  2.   

    ::SendMessage(MDIGetActive()->GetSafeHwnd(),WM_CLOSE,0,0);
      

  3.   

    vcmute(横秋)所言即是,但我如何得到前一个窗口的指针呢,
    ::SendMessage(MDIGetActive()->GetSafeHwnd(),WM_CLOSE,0,0);试了一下
    好像只是关闭当前新建的窗口
      

  4.   

    ::PostMessage(hWnd,WM_CLOSE,0,0);
      

  5.   

    那 怎样枚举所有的窗口呢?另外 oyljerry(【勇敢的心】→ ㊣X-Man㊣) 你说的函数里的hWnd参数怎样得到?谢谢!
      

  6.   

    //可以如下枚举窗口,然后.......for(CFrameWnd *pFrame = AfxGetApp()->m_pMainWnd->GetActiveFrame(); pFrame != NULL; pFrame=(CFrameWnd *)pFrame->GetNextWindow())
    {
    CView * pView = pFrame->GetActiveView();
                      if(pView->IsKindOf( RUNTIME_CLASS( CTextView ))
                      {  ((CCMDIChildWnd*)pFrame)->MDIDestroy(); }
    }// 关闭某个子窗口的方法,自己去写,不过我大致写了一下,应该可以。
      

  7.   

    使用一下两个函数:
    在EnumChildProc里::PostMessage(hWnd,WM_CLOSE,0,0);EnumChildWindows
    The EnumChildWindows function enumerates the child windows that belong to the specified parent window by passing the handle to each child window, in turn, to an application-defined callback function. EnumChildWindows continues until the last child window is enumerated or the callback function returns FALSE. BOOL EnumChildWindows(
      HWND hWndParent,         // handle to parent window
      WNDENUMPROC lpEnumFunc,  // pointer to callback function
      LPARAM lParam            // application-defined value
    );EnumChildProc
    The EnumChildProc function is an application-defined callback function used with the EnumChildWindows function. It receives the child window handles. The WNDENUMPROC type defines a pointer to this callback function. EnumChildProc is a placeholder for the application-defined function name. BOOL CALLBACK EnumChildProc(
      HWND hwnd,      // handle to child window
      LPARAM lParam   // application-defined value
    );
      

  8.   

    可以用EnumChildWindows,然后比较窗口标题来判断。
      

  9.   

    参考http://community.csdn.net/Expert/topic/4002/4002033.xml?temp=.7381555
    将EnumDesktopWindows换成EnumChildWindows,将你一个参数改为主窗口句柄