Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / MFC

A Button with Rollover Behavior using C++

Rate me:
Please Sign up or sign in to vote.
1.69/5 (25 votes)
7 Jan 2003 123.9K   1.7K   44   10
This class provides a button with rollover behavior

Sample Image - demo.jpg

Introduction

CRolloverButton is a CButton derived class. It provides a button with rollover behavior known from many webpages. The bitmaps must consist of three pictures for the different states (using the following order normal, rollover, disabled) of the button.

Usage of CRolloverButton

  • In your resource editor, create a button (do not set the 'owner draw' property).
  • Use classwizard to create a CButton object in your dialog.
  • Include the "rolloverbutton.h" file in your dialog class file.
  • Rename the CButton object type to CRolloverButton.
  • Call the SetBitmaps function in order to assign your bitmap to the new button.

SetBitmaps

C++
CRolloverButton::SetBitmaps(UINT nID, int nWidth, int nHeight, COLORREF crTransparentMask)
  • nID - ID of a bitmap resource
  • nWidth - Width of one image
  • nHeight - Height of your image
  • crTransparentMask - color displayed transparently (normally RGB(255, 255, 255) Magenta)

Example

C++
BOOL CButtonTestDlg::OnInitDialog()
{
  CDialog::OnInitDialog();
  m_btn_OK.SetBitmaps(IDB_BITMAP1, 18, 20, RGB(255, 0, 255));
  return TRUE;
}

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
Systems Engineer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralBorder at click Pin
stephanl211116-Mar-04 1:45
stephanl211116-Mar-04 1:45 
Generalis it possible in C# Pin
Paresh Gheewala8-Jan-03 8:07
Paresh Gheewala8-Jan-03 8:07 
GeneralRe: is it possible in C# Pin
datenkabel12-Sep-03 6:06
datenkabel12-Sep-03 6:06 
QuestionWhat is it? Pin
Dave_3-Jan-03 8:21
Dave_3-Jan-03 8:21 
AnswerRe: What is it? Pin
Craig Muller3-Jan-03 11:24
Craig Muller3-Jan-03 11:24 
AnswerIt seems a bad copy of CButtonST Pin
Davide Calabro8-Jan-03 2:50
Davide Calabro8-Jan-03 2:50 
GeneralRe: It seems a bad copy of CButtonST Pin
Larry Antram8-Jan-03 18:35
Larry Antram8-Jan-03 18:35 
GeneralSome comments... Pin
Nitron3-Jan-03 6:24
Nitron3-Jan-03 6:24 
GeneralRe: Some comments... Pin
l a u r e n3-Jan-03 8:22
l a u r e n3-Jan-03 8:22 
GeneralRe: Some comments... Pin
Nitron3-Jan-03 12:44
Nitron3-Jan-03 12:44 

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.