A project I have been working on requires a certain amount of visual flair. I created a set of visual elements which are unique, yet familiar enough to users that they are not confused by the control. One of these controls is the BounceButton; I will post other controls later as I get time.

Inspiration for the bounce button actually came from a visually similar Macintosh control. I am using the BounceButton as a replacement for checkboxes and radiobuttons. CBounceButton inherits from the MFC CButton class.


CBounceButton is simple to use. Include the header and implentation files in your project. #include the BounceButton header file in the header file of whatever dialog or window you plan to use the BounceButton in. Simple stuff.

CBounceButton is an owner-drawn button, but you don't have to worry about it because it automatically sets the BS_OWNERDRAW style. In your dialog resources, create a button with the desired text. The button will need to be longer than usual, because the button and text must fit into the rectangle. CBounceButton can wrap the text, but text wrapping doesn't always look nice. You can be quite generous with the size because the button borders will not be visible to the end user. The screenshot of the example's dialog resource gives a good idea of what needs to be done:

In your code, you generally handle the BounceButton like a regular button. CBounceButton provides some methods that allow you to use it like a radio button. The example illustrates the toggling and enable/disable actions that are useful.

CBounceButton is mouse-aware, or in other words a focus rectangle will be drawn around the text if the mouse cursor moves over the button or text. I used a CRgn to test for this, so the focus rect does not appear if the mouse is over client area "whitespace". Tooltips, which are also demonstrated in the example, do not (yet) provide this test, so tooltips will fire when the mouse is anywhere over the client rect. This behavior is not a problem for my app, so I didn't bother to go into it further. If somebody has a good solution, let me know and I'll incorporate it into the code.

CBounceButton is not tested with Unicode, but it I'm not aware of any reason why it would not. The example project compiles cleanly with level 4 on Visual Studio 5. Anyone may use this code; no acknowlegement of me is required. However, some of the CBounceButton code is not mine (see next paragraph), so please be respectful of Chris and follow his acknowledgement request, which is included in the source code.

That's about it. Many thanks to Chris Maunder; his many postings have been very valuable to me. The code that draws the shading on the button is lifted from his round button class.

Download demo project - 18.8 KB

Download source - 6 KB


  • Nice touch

    Posted by Legacy on 05/20/1999 12:00am

    Originally posted by: Nathan Pearce

    It's nice to see some controls other than the standard microsoft ones.

    • a

      Posted by yonemitsu on 08/19/2007 08:52pm


Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there's simply not enough quality talent to go around. In response, companies often resort to inferior solutions -- hiring substandard developers and engineers, recruiting talent on a part-time or temporary basis, poaching people from competitors, or burdening an already stressed IT staff for more of their labor. Fortunately, there's a better solution. Read this white paper to learn the business value of …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date