viksoe.dk

Skinned Button control

Skinned Button control


This article was submitted .


This is a WTL version of Shinya Miyamoto's Windows Blinds skinned button. The original MFC source code can be found on the CodeProject programming site.

It took me a while to discover this control and its fine ability to not only create nicely drawn buttons - but also to have a wealth of different skins to choose from. Just look at the skinz.org web-site to try out some different themes.

The button lacks my offscreen memory device, so it flickers a bit. But instead I fixed a few problems and added limited support for checkbox behaviour.

The button also include support for 256 coloured displays
On my old Amiga computer I always enjoyed to fiddle with palettes. However, on MS Windows they are a pain! Palettes are needed when a control have to support 256 colour desktops. The idea with palette support for this control is that you either extract the palette of the button bitmap or supply a uniform/merged application-wide palette and assign it to the control. The control then uses the palette to display the state image (more) correctly on the 256 colour display.
Assign the palette before assigning the button bitmap. Don't assign a palette if the system is not "palettized".

How to use it

Place a button on a dialog.
Then add a member variable to your dialog implementation file...
CSkinnedButtonCtrl m_ctrlButton;
In the OnInitDialog() event handler, add the following lines:
LRESULT OnInitDialog(UINT /*uMsg*/, 
                     WPARAM /*wParam*/, 
                     LPARAM /*lParam*/, 
                     BOOL& /*bHandled*/)
{
  ...
  m_ctrlButton.SubclassWindow(GetDlgItem(IDC_BUTTON1));
  m_ctrlButton.SetBitmap(IDB_AQUA);
  ...
}
There are some additional arguments to SetBitmap which allow you to configure how many state images the bitmap contains and how the button image should be stretched to accomodate different button sizes.

Add the following reflection macro to your main message map:

BEGIN_MSG_MAP(CMainDlg)
  ...
  REFLECT_NOTIFICATIONS()
END_MSG_MAP()

Finally add a bitmap with the identifier IDB_AQUA to the project. There are some sample bitmaps included with the code to play with.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 7.0 Library

See Also

Another sample with DIB controls

Download Files

DownloadSource Code and sample bitmaps (14 Kb)

To the top