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 » Changing image on the CExtToolControlBar button Collapse All
Subject Author Date
Artur Shingirei Apr 9, 2004 - 7:18 AM

Hello.

Hello.

Whether there is an opportunity to change the image on the button dynamically?
Button is a button on toolbar panel (CExtToolControlBar)

Technical Support Apr 9, 2004 - 8:45 AM

Dear Artur,

Of course, you can change menu/toolbar icons dynamically.

The Prof-UIS toolbar stores only command identifiers of its buttons. When it needs an icon, the toolbar uses it from the command manager. Please use the command manager’s CmdSetIcon() method. The function below sets a new icon (specified by the nIconID variable) to the command identifier (specified by the nCmd variable).

Please note, this code associates a new icon with a specified command identifier and new icon will be set to all the toolbar/menu items with the same identifier.

void CMainFrame::SetCmdIcon( UINT nCmd, UINT nIconID ) 
{
    HICON hNewIcon = NULL;
    HINSTANCE hInstResource =
        AfxFindResourceHandle(
            MAKEINTRESOURCE( nIconID ),
            RT_GROUP_ICON
        );
    ASSERT( hInstResource != NULL );
    if( hInstResource != NULL ) {
        hNewIcon =
            (HICON)::LoadImage(
                hInstResource,
                MAKEINTRESOURCE( nIconID ),
                IMAGE_ICON,
                16, // icon’s width, in pixels 
                16, // icon’s height, in pixels
                0
            );
        ASSERT( hNewIcon != NULL );
    }
    if( hNewIcon != NULL ){
        g_CmdManager->CmdSetIcon( 
            g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ), 
            nCmd,  
            hNewIcon, 
            true (false - use hIcon as is, true - store cloned hIcon)
        );
        
        // If a new icon is of the same size as the previous you should invalidate your toolbar, 
        // otherwise, you need to recalculate the layout of toolbar’s parent frame:
        
        if(m_wndToolBar .IsVisible() ){
            m_wndToolBar.GetParentFrame()->RecalcLayout();
            m_wndToolBar.Invalidate();
            m_wndToolBar.UpdateWindow();
        }
    }
}