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

  • Is your sales and operations planning helping or hurting your bottom line? Here are 5 useful tips from the experts at Quintiq to guide you to a better S&OP strategy.

  • Savvy enterprises are discovering that the cloud holds the power to transform IT processes and support business objectives. IT departments can use the cloud to redefine the continuum of development and operations—a process that is becoming known as DevOps. Download the Executive Brief DevOps: Why IT Operations Managers Should Care About the Cloud—prepared by Frost & Sullivan and sponsored by IBM—to learn how IBM SmartCloud Application services provide a robust platform that streamlines …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds