Introduction
I was tasked with writing an application that was to look and behave like XP Media Center 2005. I found that the templates for plug-ins provided in the Media Center SDK were nowhere near as good looking as the actual Media Center. Being a VC++ programmer, I found that a plug-in would not give me the power I needed. This is common with Microsoft, if you want any nice looking GUI classes, you must write them yourself (Visual Studio, Office). I decided to write an application from scratch.
Background
I love the Media Center animated buttons; first, I wrote a class using two animated GIFs. It was sloppy and just didn't seem right to me. Then, I took the Media Center resource DLL apart and examined all of the images. I noticed that each button consisted of three images and a Wav file. The two main images are alpha blended on a timer, and the third image is for clicked animation. I was impressed. Great idea, I wish I thought of it. I had to settle for copying their technique.
Environment
This project was built and tested on Windows 2000 and Windows XP, using Visual Studio 6 SP5 and the Microsoft Platform SDK (Feb 2003).
Using the code
- The
MCButton
class relies on three images, the Wav file is optional. Add "MCButton.h" and "MCButton.cpp" to your project, and the three images to your resources. In the test app, the resources are defined as IDB_BUTTON_FIRST
, IDB_BUTTON_LAST
, and IDB_BUTTON_PRESSED
. Subclass a button on any dialog, and set the images with the SetImages(UINT, UINT, UINT)
member function;
- (Optional) Add a Wav file resource to play when the button is clicked.
- In the window initialization, add the
CMCButton
methods:
BOOL CMainDlg::OnInitDialog()
{
m_Button.SubclassDlgItem(IDC_BTN, this);
m_Button.SetImages(IDB_BUTTON_FIRST, IDB_BUTTON_LAST,
IDB_BUTTON_PRESSED);
m_Button.SetClickedSound(IDR_WAVE_SELECT);
m_Button.Start();
Change Log
- September 27th 2006: I eliminated GLOBAL.h, and added a function to set all images at once for easier incorporation into any project. I am terrible at writing, so I rewrote the article because I needed the practice. I also added an animated GIF so that you may see exactly what the button does without having to download it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.