Click here to Skip to main content
15,886,075 members
Articles / Desktop Programming / MFC
Article

XP Media Center Animated Button Control

Rate me:
Please Sign up or sign in to vote.
4.60/5 (27 votes)
27 Sep 20062 min read 162.8K   5.8K   80   22
Drop-in animated button class that emulates the XP Media Center 2005 buttons.

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

  1. 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;
  2. (Optional) Add a Wav file resource to play when the button is clicked.
  3. In the window initialization, add the CMCButton methods:
    BOOL CMainDlg::OnInitDialog()
    {
        // ...
        // Setup MCButton
         m_Button.SubclassDlgItem(IDC_BTN, this);
         m_Button.SetImages(IDB_BUTTON_FIRST, IDB_BUTTON_LAST, 
                            IDB_BUTTON_PRESSED);
         m_Button.SetClickedSound(IDR_WAVE_SELECT); // Optional
         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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHelp me!!.How can change the icon inside CMCButton? Pin
wpwneh33314-Mar-08 6:09
wpwneh33314-Mar-08 6:09 
AnswerRe: Help me!!.How can change the icon inside CMCButton? Pin
JJMatthews15-Mar-08 5:59
JJMatthews15-Mar-08 5:59 
GeneralPlease help! Pin
Jack691048714-Jun-07 19:35
Jack691048714-Jun-07 19:35 
GeneralRe: Please help! Pin
JJMatthews5-Jun-07 17:37
JJMatthews5-Jun-07 17:37 
You probably need platform sdk.
GeneralRe: Please help! Pin
Jack691048715-Jun-07 22:45
Jack691048715-Jun-07 22:45 
GeneralRe: Please help! Pin
JJMatthews6-Jun-07 7:33
JJMatthews6-Jun-07 7:33 
GeneralRe: Please help! Pin
Jack691048716-Jun-07 17:35
Jack691048716-Jun-07 17:35 
GeneralI need help Pin
bahzad325-May-07 22:51
bahzad325-May-07 22:51 
GeneralRe: I need help Pin
JJMatthews31-May-07 6:40
JJMatthews31-May-07 6:40 
Generalhelp~ Pin
alexsando16-Mar-07 3:51
alexsando16-Mar-07 3:51 
GeneralRe: help~ Pin
JJMatthews20-Mar-07 8:23
JJMatthews20-Mar-07 8:23 
GeneralThank's you Pin
Soenson7-Jan-07 23:44
Soenson7-Jan-07 23:44 
GeneralRe: Thank's you Pin
mds1236-Apr-07 23:12
mds1236-Apr-07 23:12 
QuestionWhere is the version of 27th 2006 Pin
Dibi7-Nov-06 0:48
Dibi7-Nov-06 0:48 
AnswerRe: Where is the version of 27th 2006 Pin
JJMatthews7-Nov-06 2:33
JJMatthews7-Nov-06 2:33 
JokeGood Job Pin
OscarTV11-Oct-06 22:26
OscarTV11-Oct-06 22:26 
QuestionNeed Help???? Pin
Chhoto Bou3-Jul-06 19:41
Chhoto Bou3-Jul-06 19:41 
AnswerRe: Need Help???? Pin
JJMatthews6-Oct-06 19:57
JJMatthews6-Oct-06 19:57 
GeneralNeed Help!!!!!!! Pin
Chhoto Bou3-Jul-06 18:59
Chhoto Bou3-Jul-06 18:59 
GeneralRe: Need Help!!!!!!! Pin
Chhoto Bou3-Jul-06 19:02
Chhoto Bou3-Jul-06 19:02 
GeneralC# Pin
bryan_2000024-Nov-05 8:41
bryan_2000024-Nov-05 8:41 
GeneralAwesome Pin
Steve Messer20-Aug-05 10:28
Steve Messer20-Aug-05 10:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.