Click here to Skip to main content
Licence 
First Posted 28 Jul 2001
Views 82,846
Downloads 2,339
Bookmarked 48 times

Moveable \ Resizable Runtime Hover Buttons with ToolTips

By Fred Ackers | 28 Jul 2001
An article on creating changable buttons
1 vote, 14.3%
1

2

3
1 vote, 14.3%
4
5 votes, 71.4%
5
4.19/5 - 10 votes
μ 4.19, σa 2.62 [?]

Sample Image - hoverbuttonex.jpg

Introduction

I orginally found CHoverButton by Nick Albers and liked the HoverButton idea, however it did not have enough versatility for what I wanted. There was a good start with the MouseHover\Leave code though. I wanted to be able move and resize the buttons at runtime. I also wanted to be able to stretch the bitmaps as well as load the hover images from a horizontal or veritcal layout. I also needed the buttons to draw as regular buttons just in case no bitmaps where loaded. Thus CHoverButtonEx is created.

To make use of the CHoverButtonEx class simply create a button on your dialog and change it from CButton to CHoverButtonEx.

#include "hoverbutton.h"
...
CHoverButtonEx m_hoverbtn;

if no bitmaps or tooltips are needed, then you are done. If you need Bitmaps, then simply call LoadBitmap(IDB_Bitmap); or else LoadBitmapFromFile("Bitmap.bmp");. LoadBitmap takes an image that has 3 equal sized parts. The size of each bitmap should be width (or height) / 3 = image size.

Call SetHorizontal(TRUE); for horizontal images, SetHorizontal(FALSE); for vertical images before calling LoadBitmap. Images should be laid out as:

Next we add tooltips by calling SetToolTipText(UINT nResourceStringID, bActivate = TRUE) or else as SetToolTipText(CString spText, bActivate = TRUE). Activate is set to true to create the Tooltip and tell it to show if the mouse hovers. If Activate == FALSE, then the ToolTip will not show when the mouse hovers over the button. SetToolTipText() will create the ToolTip and set its text at the same time. Well what if I want to change the ToolTip text? Then you merely call

DeleteToolTip();
SetToolTipText("My string here");

This will delete the previous tooltip we created and create a new one with the proper text. Why don't we just reset the text you ask? Ideally that would work, however, when the button is resizeable, merely setting the text to a new string does not work. We have to delete the tooltip and recreate it with the proper dimensions and text.

To allow moving and resizing of the button at runtime, we merely call SetMoveable() and this will allow moving or resizing at runtime. Moving is done at runtime by Right Clicking and dragging the button then Left Clicking where you want to place the object. Resizing is done by holding down the Control Key and Right Clicking the Button, then LeftClicking when the button is resized to what you want. Thus our code to use this class looks like this in our header file:

#include "hoverbutton.h"
...
...
...
CHoverButtonEx m_hover;

And like this in our .cpp file:

m_hover.SetHorizontal(TRUE); // Images are laid out horizontally
m_hover.LoadBitmap(IDB_HOVER);//Load from resource
CString hover=_T("Hover Button");//ToolTip text
m_hover.SetMoveable();// Allow moving and resizing
m_hover.SetToolTipText(hover);//Create the ToolTip

The functions to handle these processess are pretty well documented in the code. Enjoy!

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

About the Author

Fred Ackers

Web Developer

United States United States

Member
Programming using MFC and ATL for almost 12 years now. Currently studying Operating System implementation as well as Image processing. Previously worked on DSP and the use of FFT for audio application. Programmed using ADO, ODBC, ATL, COM, MFC for shell interfacing, databasing tasks, Internet items, and customization programs.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionRe: License Pinmembermla15411:10 1 Jul '09  
GeneralBitmap PinmemberAmit kumhare23:21 24 Apr '07  
GeneralRe: Bitmap PinsupporterFred Ackers14:52 25 Apr '07  
GeneralGood Article.. some suggestion.. [modified] Pinmemberbootflag16:00 12 Jan '07  
GeneralRe: Good Article.. some suggestion.. PinmemberMohammadj1:38 7 Apr '09  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 29 Jul 2001
Article Copyright 2001 by Fred Ackers
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid