<!-- Download Links -->
<!-- Article image -->
<!-- Main HTML starts here -->
I orginally found
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
if no bitmaps or tooltips are needed, then you are done. If you need Bitmaps,
then simply call
LoadBitmap(IDB_Bitmap); or else
LoadBitmap takes an image that has 3 equal sized parts. The size of each bitmap
width (or height) / 3 = image size.
SetHorizontal(TRUE); for horizontal images,
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.
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
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:
And like this in our .cpp file:
m_hover.SetHorizontal(TRUE); m_hover.LoadBitmap(IDB_HOVER);CString hover=_T("Hover Button");m_hover.SetMoveable();m_hover.SetToolTipText(hover);
The functions to handle these processess are pretty well documented in the code. Enjoy!