Professional UI Solutions
Site Map   /  Register


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 » Multi colored buttons on theme Collapse All
Subject Author Date
Ian Hollamby Apr 9, 2008 - 10:50 AM

Hi, I have seen that you can change the orange color of buttons in the Obsidian theme by creating your own paint manager and changing the InitTranslatedColors function, but is there a way to create different colored buttons in the same theme at the same time?

I would like to create buttons with different functionality and give instant recognition to the user through the background colour of the button on the same dialog, perhaps also having the option to change the foreground color too. In our application there is likely to be 50 to 100 buttons on a form so the easier the better!



Ian Hollamby Aug 6, 2008 - 9:36 AM

I did get this to work in the end...just being a dork!

However I would still like to know whether there is a cleaner solution for this.



Technical Support Aug 9, 2008 - 12:16 PM

No, there are no other solutions but overriding the PaintPushButton() virtual method.

Ian Hollamby Aug 4, 2008 - 5:58 AM

What I would prefer is for the button to draw itself using the selected paint manager, apart from when the background color has been forced. This means on creation the buttons would all be the same and the program would dynamically how the button was displayed depending on the background color.

In order to experiment with this I changed the ExtPaintManager.cpp file in the library to change the behaviour of the CExtPaintManagerOffice2007_R2_Obsidian::PaintPushButton() function.

The first few lines were changed to:


ASSERT( dc.GetSafeHdc() != NULL );


this );// If user has forced back color then move from theme


PaintNormalPushButton( dc, _ppbd );

if( _ppbd.m_clrForceBk != ((COLORREF)-1L ) )


and the CExtPaintManager::PaintPushButton() function was copied to the new CExtPaintManagerOffice2007_R2_Obsidian::PaintNormalPushButton() function.

When I tried this using a modified version of the Prof-UIS Controls project, the new function was being called but the buttons did not change their appearance, ie they displayed the bitmap regardless of the background color being set.

Can you see why this would not work or if there is a cleaner way to do this?




Technical Support Aug 6, 2008 - 11:16 AM

Actually you don’t need to copy the content of the CExtPaintManagerOffice2007_R2_Obsidian::PaintPushButton() method. Just invoke the base class method as below:

void CExtPaintManagerOffice2007_R2_Obsidian::PaintPushButton(
            CDC & dc,
            CExtPaintManager::PAINTPUSHBUTTONDATA & _ppbd
            ASSERT_VALID( this );
            ASSERT( dc.GetSafeHdc() != NULL );


            if( _ppbd.m_clrForceBk != ((COLORREF)-1L ) )


Ian Hollamby Aug 4, 2008 - 6:12 AM

The code snippet in the previous post is out of order for some reason and should read


ASSERT( dc.GetSafeHdc() != NULL );

// If user has forced back color then move from theme

if(  _ppbd.m_clrForceBk != ((COLORREF)-1L ) )

PaintNormalPushButton( dc, _ppbd );

Technical Support Apr 11, 2008 - 7:08 AM

Although the CExtButton::_RenderImpl() virtual method is used for drawing the button in fact it is drawn by the currently selected paint manager (in the CExtPaintManager::PaintPushButton() virtual method where it is overridden in the corresponding paint manager classes). So you can create a CExtButton-derived class and override the _RenderImpl() virtual method. There you can copy the code from CExtPaintManagerSkin::PaintPushButton() and change the part where the background is painted. The new painting algorithm should check some button property and paint the background differently.

Note there is another way. You can use the CExtButton::SetBkColor() method for changing the background color. But the SetBkColor() method works only for the Office 2000/XP/2003 and Visual Studio 2005 themes. Otherwise it is useless because the buttons in the Office 2007 themes are based on bitmaps stored in Prof-UIS resources and APIs like button background color does not work in these themes. In this case you can directly assign the paint manager that will be used by button. You can read more about this here

Ivan Surzhenko Apr 15, 2008 - 1:15 AM

Yes. But overriding for 50 to 100 buttons... It`s crazy work.

Ivan Surzhenko Apr 9, 2008 - 10:36 PM

Hi. ProfUIS is not support manual skinning of different controls. But it has been researched by me... I find some solutions of the problem. See;/p>

If you will be have some questions or notes, pls, post it in this thread.

P.S. I`m not TS.