CBounceButton

Background

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.

Use

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



Comments

  • 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

      a

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

Top White Papers and Webcasts

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

Most Popular Programming Stories

More for Developers

RSS Feeds