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 » CExtPropertyGridCtrl Adding Buttons to Toolbar Collapse All
Subject Author Date
David Baginski Mar 23, 2010 - 1:27 PM

Hello,


I have seen two other posts with this question but I still have trouble making the buttons display in the toolbar.  I have created a new project using the ProfUIS application wizard.  I then turned the Empty controlbar in the sample code into a ExtPropertyGridCtrl.  This works fine.  I then derived my own class from CExtPropertyGridCtrl and overrode the virtual method OnPgcCreateBars() to add the application about button to the toolbar.  However, the button does not display although the separator I added does display.  It appears that the button is in the toolbar however because the status bar will update the displayed message when I hover the cursor over the location that I expect the button to be displayed.  However, the button does not appear to be painting.  Do I need to override the OnCmd method before the button will paint?


Here is my code for OnPgcCreateBars():


bool CMyPropertyGridCtrl::OnPgcCreateBars()
{
    ASSERT_VALID( this );

    if( ! CExtPropertyGridCtrl::OnPgcCreateBars() )
        return false;

    CWnd * pWnd = GetChildByRTC( RUNTIME_CLASS(CExtPropertyGridToolBar) );
    if( pWnd != NULL )
    {
        ASSERT_VALID( pWnd );
        CExtPropertyGridToolBar * pToolBar = STATIC_DOWNCAST( CExtPropertyGridToolBar, pWnd );
        pToolBar->m_bForceBalloonGradientInDialogs = false;

        VERIFY( pToolBar->InsertButton( -1 ) );
        VERIFY( pToolBar->InsertButton( -1, ID_APP_ABOUT ) );
    }
    return true;
}



I can send you the whole project if that would help.


Thanks,


Dave


 

David Baginski Mar 25, 2010 - 12:17 PM


 


OK it works now, thank you! 


If anybody else is looking at this, here is the source for the other two methods that are required to get user buttons to work on the property grid toolbar.  In this case, the button I am using is defined in the IDR_MAINFRAME resource (about).  You will need to include the correct resource here for your application.  And you will need to replace ID_APP_ABOUT with the correct command as well.


 




void CMyPropertyGridCtrl :: PreSubclassWindow()
{
    CExtPropertyGridCtrl::PreSubclassWindow();
    ASSERT( ! m_strCommandProfile.IsEmpty() );
    VERIFY(
        g_CmdManager->UpdateFromToolBar(
            LPCTSTR( m_strCommandProfile ),
            IDR_MAINFRAME
            )
        );
}


 




BOOL CMyPropertyGridCtrl::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
    switch( nID ) 
    { 
    case ID_APP_ABOUT: 
        switch( nCode )
        {
        case CN_COMMAND:
            CExtPaintManager::stat_PassPaintMessages(); 
            dynamic_cast<CProfPropGridApp*>(AfxGetApp())->OnAppAbout();
        break;

        case CN_UPDATE_COMMAND_UI:
            //TRACE("CN_UPDATE_COMMAND_UI\n");
            ASSERT( pExtra != NULL );
            ((CCmdUI*)pExtra)->Enable( TRUE );
        break;
        } // switch( nCode )

        return TRUE;

    } // switch( nID )


    return CExtPropertyGridCtrl::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}



Technical Support Mar 25, 2010 - 2:34 AM

There is a ready-to-use example of how to insert custom buttons into a property grid’s toolbar. It’s in the Prof-UIS source code for the CExtPPVW template decorator class which adds printing and print previewing features to other controls. A specialized version of this class (CExtPPVW < CExtPropertyGridCtrl >) inserts print and print preview toolbar buttons. This is the last class in the ../Prof-UIS/Include/ExtPrint.h and ../Prof-UIS/Src/ExtPrint.cpp files. There are three important methods:

1) The CExtPPVW < CExtPropertyGridCtrl > :: PreSubclassWindow() virtual method updates the property grid’s command profile with the icons from the IDR_EXT_TOOLBAR_PPW toolbar resource. You didn’t do that. This is why you didn’t see the icon on your About toolbar button. The CExtBarButton toolbar button objects inside the CExtToolControlBar toolbar control does not contain icons. The toolbar buttons used the command icons stored in the command manager. Your About toolbar button is not able to find the ID_APP_ABOUT command icon in the command manager.

2) The CExtPPVW < CExtPropertyGridCtrl > :: OnPgcCreateBars() virtual method inserts the toolbar buttons. It’s similar to your method. Your method is OK.

3) The CExtPPVW < CExtPropertyGridCtrl > :: OnCmdMsg() virtual method handles and updates the toolbar button commands. You should add the similar method into your property grid class.

David Baginski Mar 23, 2010 - 1:32 PM

Second question, if I have to override OnCmdMsg, what should I add to route the ID_APP_ABOUT command?