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 General Discussion » Error when insert a new tab in ribbonbar control at run time Collapse All
Subject Author Date
Mr Tran Aug 26, 2008 - 1:38 AM

I’m using Win XP SP2 and Prof-UI ver 2.82 for MFC. I have a application MDI like "RibbonBarMDI" example. I want to insert a new tab at run time and I found "DynamicRibbonPageInserting" example in "Prof-UIS General Discussion" forum but when i applied block code to "RibbonBarMDI" example :

( I want to click Copy button in Home Tab, the View Tab is visible )

afx_msg void OnHello();

ON_COMMAND(ID_EDIT_COPY,OnHello)

void CMainFrame::OnHello()
{
    // TODO: Add your command handler code here
    
    ASSERT_VALID( this );

    // STEP 1: remove previous new ribbon content
    INT nSel = 0;
    if( m_pRibbonNode != NULL )
    {
        // remember selection index
        nSel = m_wndRibbonBar.Ribbon_GetTabPageRootNode()->PageSelectionGet();
        // delete content
        m_wndRibbonBar.SetButtons( NULL );
        delete m_pRibbonNode;
        m_pRibbonNode = NULL;
    }

    // STEP 2: create new ribbon content
    m_pRibbonNode = new CExtRibbonNode;
    CExtRibbonNodeTabPageCollection * pRibbonNodeTabPageCollection =
        new CExtRibbonNodeTabPageCollection;
    m_pRibbonNode->InsertNode( NULL, pRibbonNodeTabPageCollection );
    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Home() );
    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Insert() );
    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_PageLayout() );
    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_References() );
    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Mailings() );
    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Review() );
    // pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_View() );
    ////////////////////////    
    // this assumed to be your dynamic page
    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_View() );
    ////////////////////////    

    pRibbonNodeTabPageCollection->PageSelectionSet( nSel );

    CExtRibbonNodeRightButtonsCollection * pRibbonNodeRightButtonsCollection =
        _InitRibbon_RightButtonsCollection();
    m_pRibbonNode->InsertNode( NULL, pRibbonNodeRightButtonsCollection );
    CExtRibbonNodeQuickAccessButtonsCollection * pRibbonNodeQuickAccessButtonsCollection =
        _InitRibbon_QuickAccessButtonsCollection();
    m_pRibbonNode->InsertNode( NULL, pRibbonNodeQuickAccessButtonsCollection );

    CExtRibbonNodeFile * pRibbonNodeFile = _InitRibbon_FileMenu();
    m_pRibbonNode->InsertNode( NULL, pRibbonNodeFile );

    m_wndRibbonBar.SetButtons( m_pRibbonNode );
    VERIFY(
        m_wndRibbonBar.
        MenuInfoGetDefault()->
        AccelTableLoad( IDR_MAINFRAME )
        );
    VERIFY(
        m_wndRibbonBar.Ribbon_FileButtonGet() ->
        m_iconForLargeMode.m_bmpNormal.
        LoadBMP_Resource( MAKEINTRESOURCE( IDB_BITMAP_SMALL_ICON ) )
        );

    // STEP 3: display changes
    m_wndRibbonBar._RecalcPositionsImpl();
    m_wndRibbonBar.Invalidate();
    m_wndRibbonBar.UpdateWindow();
}

After run application, I click normally on Copy button in Home Tab, the View Tab is visible, but when i click quickly on Copy button ( repeat some time) I’d received a error message :

Photobucket

Please help me to fix it ! Thanks !!

Mr Tran Aug 28, 2008 - 10:05 AM

Is there any way else to fix it , besides the way to update Prof-UI from version 2.82 to version 2.83 ?? Thanks for your answer.

Technical Support Aug 28, 2008 - 12:34 PM

The CExtRibbon*** classes and CExtNCW template classes were greatly refactored in 2.83. We believe it’s possible to insert these classes from 2.83 into 2.82 but, as a result, you will get some kind of mixed Prof-UIS version which is very close to 2.83. Why don’t just switch to 2.83?

Mr Tran Aug 27, 2008 - 7:20 PM

I’m using Visual C++.NET 2005 Service Pack 1 and Prof-UI v2.82. After run application, I click normally on Copy button in Home Tab, the View Tab is visible, but when i click very fast on Copy button ( repeat some time) I’d received a above error message.

Technical Support Aug 28, 2008 - 8:17 AM

This information explains everything. Such issue was present in ribbon bar in Prof-UIS 2.82. It’s fixed in 2.83. That is why we didn’t see any crashes. We run your test project OK because we compiled it with 2.83.

Mr Tran Aug 26, 2008 - 11:49 PM

The code that I do the your advice:




afx_msg void OnHello();


CExtRibbonNode * m_pRibbonNodeTemp;


ON_COMMAND(ID_EDIT_COPY,OnHello)



void CMainFrame::OnHello()



{

  

    ASSERT_VALID( this );



    // STEP 1: remove previous new ribbon content



    INT nSel = 0;



    if( m_pRibbonNode != NULL )



    {

        // remember selection index

        nSel = m_wndRibbonBar.Ribbon_GetTabPageRootNode()->PageSelectionGet();

        // delete content

        m_wndRibbonBar.SetButtons( NULL );  


  m_pRibbonNodeTemp =  m_pRibbonNode ;



    }





    // STEP 2: create new ribbon content



    m_pRibbonNode = new CExtRibbonNode;



    CExtRibbonNodeTabPageCollection * pRibbonNodeTabPageCollection =



        new CExtRibbonNodeTabPageCollection;



    m_pRibbonNode->InsertNode( NULL, pRibbonNodeTabPageCollection );



    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Home() );



    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Insert() );



    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_PageLayout() );



    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_References() );



    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Mailings() );



    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Review() );



    // pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_View() );



    ////////////////////////    



    // this assumed to be your dynamic page



    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_View() );



    ////////////////////////    







    pRibbonNodeTabPageCollection->PageSelectionSet( nSel );







    CExtRibbonNodeRightButtonsCollection * pRibbonNodeRightButtonsCollection =



        _InitRibbon_RightButtonsCollection();



    m_pRibbonNode->InsertNode( NULL, pRibbonNodeRightButtonsCollection );



    CExtRibbonNodeQuickAccessButtonsCollection * pRibbonNodeQuickAccessButtonsCollection =



        _InitRibbon_QuickAccessButtonsCollection();



    m_pRibbonNode->InsertNode( NULL, pRibbonNodeQuickAccessButtonsCollection );



    CExtRibbonNodeFile * pRibbonNodeFile = _InitRibbon_FileMenu();



    m_pRibbonNode->InsertNode( NULL, pRibbonNodeFile );



    m_wndRibbonBar.SetButtons( m_pRibbonNode );



    VERIFY(



        m_wndRibbonBar.



        MenuInfoGetDefault()->



        AccelTableLoad( IDR_MAINFRAME )



        );



    VERIFY(



        m_wndRibbonBar.Ribbon_FileButtonGet() ->



        m_iconForLargeMode.m_bmpNormal.



        LoadBMP_Resource( MAKEINTRESOURCE( IDB_BITMAP_SMALL_ICON ) )



        );





    // STEP 3: display changes



    m_wndRibbonBar._RecalcPositionsImpl();



    m_wndRibbonBar.Invalidate();



    m_wndRibbonBar.UpdateWindow();


delete m_pRibbonNodeTemp;



}


I’d still received the same error message.

Mr Tran Aug 26, 2008 - 11:44 PM

Could you tell me more detail ? Because if I do:

1.Save m_pRibbonNode pointer into m_pRibbonNodeTemp

2.Reconstruct m_pRibbonNode and assign it to ribbon bar.

3. Delete m_pRibbonNodeTemp


 afx_msg void OnHello();


CExtRibbonNode * m_pRibbonNodeTemp;



ON_COMMAND(ID_EDIT_COPY,OnHello)



void CMainFrame::OnHello()

{

    // TODO: Add your command handler code here

    

    ASSERT_VALID( this );



    // STEP 1: remove previous new ribbon content

    INT nSel = 0;

    if( m_pRibbonNode != NULL )

    {

        // remember selection index

        nSel = m_wndRibbonBar.Ribbon_GetTabPageRootNode()->PageSelectionGet();

        // delete content

        m_wndRibbonBar.SetButtons( NULL );

       // delete m_pRibbonNode;


m_pRibbonNodeTemp;


        m_pRibbonNode = NULL;

    }



    // STEP 2: create new ribbon content

    m_pRibbonNode = new CExtRibbonNode;

    CExtRibbonNodeTabPageCollection * pRibbonNodeTabPageCollection =

        new CExtRibbonNodeTabPageCollection;

    m_pRibbonNode->InsertNode( NULL, pRibbonNodeTabPageCollection );

    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Home() );

    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Insert() );

    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_PageLayout() );

    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_References() );

    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Mailings() );

    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_Review() );

    // pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_View() );

    ////////////////////////    

    // this assumed to be your dynamic page

    pRibbonNodeTabPageCollection->InsertNode( NULL, _InitRibbonPage_View() );

    ////////////////////////    



    pRibbonNodeTabPageCollection->PageSelectionSet( nSel );



    CExtRibbonNodeRightButtonsCollection * pRibbonNodeRightButtonsCollection =

        _InitRibbon_RightButtonsCollection();

    m_pRibbonNode->InsertNode( NULL, pRibbonNodeRightButtonsCollection );

    CExtRibbonNodeQuickAccessButtonsCollection * pRibbonNodeQuickAccessButtonsCollection =

        _InitRibbon_QuickAccessButtonsCollection();

    m_pRibbonNode->InsertNode( NULL, pRibbonNodeQuickAccessButtonsCollection );



    CExtRibbonNodeFile * pRibbonNodeFile = _InitRibbon_FileMenu();

    m_pRibbonNode->InsertNode( NULL, pRibbonNodeFile );



    m_wndRibbonBar.SetButtons( m_pRibbonNode );

    VERIFY(

        m_wndRibbonBar.

        MenuInfoGetDefault()->

        AccelTableLoad( IDR_MAINFRAME )

        );

    VERIFY(

        m_wndRibbonBar.Ribbon_FileButtonGet() ->

        m_iconForLargeMode.m_bmpNormal.

        LoadBMP_Resource( MAKEINTRESOURCE( IDB_BITMAP_SMALL_ICON ) )

        );



    // STEP 3: display changes

    m_wndRibbonBar._RecalcPositionsImpl();

    m_wndRibbonBar.Invalidate();

    m_wndRibbonBar.UpdateWindow();

}


 




I’d still received the same error message . I don’t know what different between deleting m_pRibbonNode and deleting m_pRibbonNodeTemp? I think it’s the same beacause it delete a area memory.

The above block code that insert dynamically tab, I refered to the project demo:


www.prof-uis.com/download/forums/DynamicRibbonPageInserting.zip





Thanks !

Technical Support Aug 27, 2008 - 11:51 AM

The test project you sent us works OK. New "Page Layout" tab page becomes inserted and appears without any crashes. We have used Visual C++ 6.0. Which version of Visual C++ you are using?

Technical Support Aug 26, 2008 - 10:35 AM

Your code deletes the m_pRibbonNode first and then re-creates it. But the objects from old command tree can be still referred from ribbon bar’s buttons. Pease do the following:

1) Save m_pRibbonNode pointer into some local variable and do not delete this pointer.

2) Construct new command tree like you do and assign it to ribbon bar.

3) Delete the saved pointer.