怎么在vc中判断一个窗口是否已经关闭

解决方案 »

  1.   

    用这个函数
    IsWindow
    The IsWindow function determines whether the specified window handle identifies an existing window. BOOL IsWindow(
      HWND hWnd   // handle to window
    );
    Parameters
    hWnd 
    [in] Handle to the window to test. 
    Return Values
    If the window handle identifies an existing window, the return value is nonzero.If the window handle does not identify an existing window, the return value is zero. Res
    A thread should not use IsWindow for a window that it did not create because the window could be destroyed after this function was called. Further, because window handles are recycled the handle could even point to a different window. 
      

  2.   

    我自己建了一个工具栏,是浮动的,可以关闭
    另外有一个菜单控制,执行时如果工具栏关闭,则重建。代码:
    int CMainFrame::OpenToolBar ()
    {
    if(!::IsWindow(m_wndToolBar.m_hWnd) )
    {
    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT , WS_CHILD | WS_VISIBLE | CBRS_TOP
        |CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndToolBar.LoadToolBar (IDR_TOOLBAR1) )//||
    //!m_wndToolBar.SetButtons(ToolsA, sizeof(ToolsA)/sizeof(UINT)))
    {
    TRACE0("Failed to create the light toolbar.\n");
    return -1;      // if failed to create
    } m_wndToolBar.EnableDocking (CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar);
    return 1;
    }
    }但是不行
      

  3.   

    显示和关闭应该用
    CFrameWnd::ShowControlBarSee Also
    CFrameWnd Overview | Class Members | Hierarchy Chart
    Call this member function to show or hide the control bar.void ShowControlBar(
       CControlBar* pBar,
       BOOL bShow,
       BOOL bDelay 
    );
    Parameters
    pBar 
    Pointer to the control bar to be shown or hidden. 
    bShow 
    If TRUE, specifies that the control bar is to be shown. If FALSE, specifies that the control bar is to be hidden. 
    bDelay 
    If TRUE, delay showing the control bar. If FALSE, show the control bar immediately. 
    来显示和隐藏工具栏,判断工具栏是否已经显示可以用
    CWnd::IsWindowVisible
    This method determines the visibility state of the specified window. BOOL IsWindowVisible( )
    const; 
    Return Value
    Nonzero if CWnd is visible, that is, has the WS_VISIBLE style bit set, and parent window is visible. Because the return value reflects the state of the WS_VISIBLE style bit, the return value may be nonzero even though CWnd is totally obscured by other windows.或者
    CControlBar* pBar;//某个工具栏的指针
    ...
    (pBar->GetStyle() & WS_VISIBLE) != 0;//说明显示了
    可以给我发email,我给你一个这方面的例子[email protected]