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

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds