Click here to Skip to main content
15,890,185 members
Articles / Desktop Programming / MFC
Article

StarControl

Rate me:
Please Sign up or sign in to vote.
4.23/5 (21 votes)
6 Feb 2004CPOL2 min read 52.1K   2.3K   24   3
An article about a star control like that included in the media library in Media Player.

Starcontrol

Introduction

I wrote a little tool for managing my videos. With this tool, I can store my videos and additional information in a database. After a while, I wanted to have a possibility to store an assessment. I found the solution in the Microsoft Media Player very good. In the media library from the Media Player, you have the possibility to assess every media file. This is done by a star control. So, I searched the Internet to find an already existing solution for such a star control which I can include into my project. But I didn't find anything, so I decided to do it myself.

First, I wrote a new class CIEStarControl which inherits from CStatic. Then, I overloaded the OnPaint() function to paint myself. Finally, I overloaded the functions OnMouseMove() and OnLeftButtonUp() to be able to react on the mouse events.

After that, I wrote a data exchange function to make the use of this control as easy as possible.

Using the class

So, what do you have to do to use this class in your own project?

  1. Add the source files (IEStarContro.cpp and IEStarControl.h) into your project.
  2. Add the bitmaps into your resource (have a look at the IEStarControl.cpp file; the bitmaps are used in the function OnPaint(), so ensure that you take the same IDs like in this function or change the IDs in this function to your own IDs).
  3. Create a static control on your dialog with the resource editor.
  4. Create a member variable (e.g. CStatic m_StarControl) for this static control into your dialog class by the class wizard.
  5. Change the type of the just created variable from CStatic to CIEStarControl by editing directly the header file.

    E.g.: CStatic m_StarControl --> CIEStarControl m_StarControl6. Include the file IEStarControl.h into the header file of the dialog class.

  6. Add an integer member variable to your dialog class (e.g. m_nStars) for storing the number of actual stars.
  7. Add the following line to your DoDataExchange(CDataExchange* pDX) function.

    E.g. DDX_IEStarControl( pDX, IDC_STAR_CONTROL, m_nStars ); (m_nStars is the variable you declared in step 7.)

  8. Now you are ready - these are all the first steps you have to do to get the control to work.

Additionally, the control provides some other functions:

  1. SetNumberOfStars( int, BOOL) - with this function, you can change to maximum number of stars which this control can work with (default: 5)
    • int - new number of stars.
    • BOOL - indicates whether the control should resize itself to ensure that all stars fit into the control.
  2. SetNumberOfStars( int ) / GetNumberOfStars() - to set / get the current number of stars.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Germany Germany
Hi, my interest in computers was born at school time while programming with Turbo Pascal. While studying information technologies I learned C, C++ and some other languages. In the practical phases I got confronted with MFC in an american company.

Now at work, I bother with the .Net framework most time. I am in an italian company providing supply chain software. I have to deal with C, C++, ASP.Net, VB.Net, C# and JavaScript.

In my spare time I am an enthusiastic motor bike driver. I like to go an tour as much as riding on a racetrack. I want to visit all european racetracks and drive on them. But for now I only drove on german racetracks.

Comments and Discussions

 
GeneralGood job, Got my 5, again Pin
Snyp7-Feb-04 8:17
Snyp7-Feb-04 8:17 
I posted a comment and I got it, using it in an activex control, good job since you actually updated and succeeded updating it to activex. Poke tongue | ;-P

Actual Linux Penguins were harmed in the creation of this message.
GeneralNice. Pin
Snyp19-Jan-04 13:07
Snyp19-Jan-04 13:07 
GeneralRe: Nice. Pin
ieaeitsch20-Jan-04 8:31
ieaeitsch20-Jan-04 8:31 

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.