Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » How to create controlbar autohidden by default? Collapse All
Subject Author Date
Dmitriy Dashevskiy Oct 22, 2005 - 8:51 AM

If I use

m_wndBar.AutoHideModeSet(true, false, true, false);

in OnCreate then bar is created and is auto hidden. Everything seams fine.

But if application is closed (saving state with CExtControlBar::ProfileBarStateSave) and then started again (loading state in OnCreate using CExtControlBar::ProfileBarStateLoad) then autohidden bars are not shown. Same behaviour is with provided Prof-UIS samples (I’ve tried DI_InnerOuterBars).

If instead bars are created not autohidden are are hidden manualy (clicking on autohide button) before closing application then everything works fine.

So, what should be done to create autohidden control bars programmatically?

Technical Support Oct 24, 2005 - 11:01 AM

You may lose the gui state only in case of MDI child windows which are destroyed automatically when the main frame window is closed. In this case, the DestroyWindow() virtual method of your MDI child windows is not invoked and, as a result, the state of the bars is not saved. If our guess is correct, just invoke the DestroyWindow() virtual method for the MDI child from the DestroyWindow() virtual method of the main frame window:

BOOL CMainFrame::DestroyWindow() 
{
    HWND hWndMdiClient = ::GetDlgItem( m_hWnd, AFX_IDW_PANE_FIRST );
    if( hWndMdiClient != NULL )
    {
        HWND hWnd = ::GetWindow( hWndMdiClient, GW_CHILD );
        for( ; hWnd != NULL; hWnd = ::GetWindow( hWndMdiClient, GW_CHILD ) )
        {
            CWnd * pWnd = CWnd::FromHandlePermanent( hWnd );
            if( pWnd != NULL )
                pWnd->DestroyWindow();
            else
                ::DestroyWindow( hWnd );
        } // for( ; hWnd != NULL; hWnd = ::GetWindow( hWndMdiClient, GW_CHILD ) )
    } // if( hWndMdiClient != NULL )
. . .
If it’s not the case, please provide us with more details.

Dmitriy Dashevskiy Oct 25, 2005 - 12:19 PM

Thanks, but lost state "happens" for CExtControlBars in CMainFrame not in CChildFrame. I was looking more into this and it gets really strange. If I add
[PRE]
m_wndResizableBar2.AutoHideModeSet(true, false, true, false);
[/pre]
in CMainFrame::OnCreate (before final RecalcLayout() ) in MDI_InnerOuterBars project then problem described above is present. But doing same thing in CMainFrame::OnCreate in MDI project
[pre]
m_wndResizableBar0.AutoHideModeSet(true, false, true, false);
[/pre]
works just fine. Could you please help figure out why.

To see the problem:
1. make mentioned modifications & compile;
2. clean the registry for corresponding application;
3. start program. Now bars docked for first time and everything is fine;
4. close application and start again. Autohidden bar dissapeared in MDI_InnerOuterBars project.

Technical Support Oct 26, 2005 - 7:38 AM

We have found the source of the problem. The CExtControlBar::ProfileBarStateLoad() method makes all the control bars hidden and sets the frame window as their parent window. The CChildFrame::OnCreate() method in the MDI_InnerOuterBars sample should set initial positions of the control bars only if the CExtControlBar::ProfileBarStateLoad() failed to load the control bars’ state. Here is the updated source code for this method:

int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
 
    ASSERT( m_hChildFrameIcon != NULL );
    SetIcon( m_hChildFrameIcon, FALSE );
    SetIcon( m_hChildFrameIcon, TRUE );
 
    // create a view to occupy the client area of the frame
    if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, 
        CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
    {
        TRACE0("Failed to create view window\n");
        return -1;
    }
 
    if(    !m_wndToolbar0.Create(
            _T("Child Toolbar 0"),
            this,
            IDR_TOOLBAR_CHILD0
            )
        || !m_wndToolbar0.LoadToolBar(IDR_TOOLBAR_CHILD0)
        )
    {
        TRACE0("Failed to create m_wndToolbar0\n");
        return -1;        // fail to create
    }
 
    if(    !m_wndToolbar1.Create(
            _T("Child Toolbar 1"),
            this,
            IDR_TOOLBAR_CHILD1
            )
        || !m_wndToolbar1.LoadToolBar(IDR_TOOLBAR_CHILD1)
        )
    {
        TRACE0("Failed to create m_wndToolbar1\n");
        return -1;        // fail to create
    }
 
    if(    !m_wndResizableBar0.Create(
            _T("Resizable Bar 0"),
            this,
            ID_VIEW_CHILDFRAME_BAR_0
            )
        || !m_wndListBox0.Create(
            WS_CHILD|WS_VISIBLE|LBS_NOINTEGRALHEIGHT,
            CRect( 0, 0, 0, 0 ),
            &m_wndResizableBar0,
            UINT( IDC_STATIC )
            )
        )
    {
        TRACE0("Failed to create m_wndResizableBar0\n");
        return -1;        // fail to create
    }
    m_wndListBox0.SetFont( CFont::FromHandle( (HFONT)::GetStockObject(DEFAULT_GUI_FONT) ) );
    m_wndListBox0.AddString( _T("CChildFrame::m_wndListBox0") );
 
    if(    !m_wndResizableBar1.Create(
            _T("Resizable Bar 1"),
            this,
            ID_VIEW_CHILDFRAME_BAR_1
            )
        || !m_wndListBox1.Create(
            WS_CHILD|WS_VISIBLE|LBS_NOINTEGRALHEIGHT,
            CRect( 0, 0, 0, 0 ),
            &m_wndResizableBar1,
            UINT( IDC_STATIC )
            )
        )
    {
        TRACE0("Failed to create m_wndResizableBar1\n");
        return -1;        // fail to create
    }
    m_wndListBox1.SetFont( CFont::FromHandle( (HFONT)::GetStockObject(DEFAULT_GUI_FONT) ) );
    m_wndListBox1.AddString( _T("CChildFrame::m_wndListBox1") );
 
    if(    !m_wndResizableBar2.Create(
            _T("Resizable Bar 2"),
            this,
            ID_VIEW_CHILDFRAME_BAR_2
            )
        || !m_wndListBox2.Create(
            WS_CHILD|WS_VISIBLE|LBS_NOINTEGRALHEIGHT,
            CRect( 0, 0, 0, 0 ),
            &m_wndResizableBar2,
            UINT( IDC_STATIC )
            )
        )
    {
        TRACE0("Failed to create m_wndResizableBar2\n");
        return -1;        // fail to create
    }
    m_wndListBox2.SetFont( CFont::FromHandle( (HFONT)::GetStockObject(DEFAULT_GUI_FONT) ) );
    m_wndListBox2.AddString( _T("CChildFrame::m_wndListBox2") );
 
    m_wndToolbar0.EnableDocking(CBRS_ALIGN_ANY);
    m_wndToolbar1.EnableDocking(CBRS_ALIGN_ANY);
    m_wndResizableBar0.EnableDocking(CBRS_ALIGN_ANY);
    m_wndResizableBar1.EnableDocking(CBRS_ALIGN_ANY);
    m_wndResizableBar2.EnableDocking(CBRS_ALIGN_ANY);
 
    if( !CExtControlBar::FrameEnableDocking(this) )
    {
        ASSERT( FALSE );
        return -1;
    }
#if (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
    if( !CExtControlBar::FrameInjectAutoHideAreas(this) )
    {
        ASSERT( FALSE );
        return -1;
    }
#endif // (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
 
    DockControlBar(&m_wndToolbar0,AFX_IDW_DOCKBAR_TOP);
    DockControlBar(&m_wndToolbar1,AFX_IDW_DOCKBAR_LEFT);
 

CWinApp * pApp = ::AfxGetApp();
    ASSERT( pApp != NULL );
    ASSERT( pApp->m_pszRegistryKey != NULL );
    ASSERT( pApp->m_pszRegistryKey[0] != _T(’\0’) );
 
    if( ! CExtControlBar::ProfileBarStateLoad(
            this,
            pApp->m_pszRegistryKey,
            pApp->m_pszProfileName,
            LPCTSTR( m_sProfileName )
            )
        )
    {
        m_wndResizableBar0.DockControlBar( AFX_IDW_DOCKBAR_TOP, 1 );
        m_wndResizableBar0.DockControlBar( &m_wndResizableBar1, true );
        m_wndResizableBar2.DockControlBar( AFX_IDW_DOCKBAR_BOTTOM, 1 );
#if (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
        m_wndResizableBar2.AutoHideModeSet( true, false, true, true );
#endif // (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
    }
 
    return 0;
}


Dmitriy Dashevskiy Oct 27, 2005 - 1:22 AM

Actually I was referring to bars crated in CMainFrame::OnCreate but there is same behaviour of bars in CChildFrame. Unfortunately your new CChildFrame::OnCreate does not change anything. I just downloaded the latest 250 to make sure that we are talking about the same code - still the same. When MDI_InnerOuterBars sample is started first time (with clean registry) - autohidden bar is shown. But in closed and restarted application bar is not shown.

Technical Support Oct 27, 2005 - 1:47 PM

We also suspect some kind of difference in the source code. Please redownload version 2.50. We also sent you a compiled sample by e-mail.

Dmitriy Dashevskiy Oct 31, 2005 - 12:58 AM

The latest version does resolve this issue. Thanks for taking care of it.