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

  • Organizations are increasingly gravitating toward mobile-first application development as they assess the need to revamp their application portfolios to support touch computing and mobility. Consumerization has brought higher expectations for application usability along with the mobile devices themselves. Enterprises are increasingly shifting their new application acquisitions and development efforts toward mobile platforms. With this backdrop, it is natural to expect application platform vendors to invest in …

  • What does it take to win? According to Jack Welch, winning in business is great because when companies win, people thrive and grow. However, it goes without saying that you have to win the right way -- cleanly and by the rules. Even the most talented businessperson with the best intentions will get nowhere unless he or she knows how to win in today's complex business world. Read this book summary to learn not only the strategies of winning, but also the value that those strategies bring to your professional …

Most Popular Programming Stories

More for Developers

RSS Feeds

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