Universal Button - beauty of HRGN

I will describe CUniButton class, which is an advanced button.  Many button classes have been coded but there is always place for more...

Why is the CUniButton useful?  Look at the snap-shot of demo application above.  It shows several buttons on the dialog.  All these GUI elements have been created from a single CUniButton class.  They are clickable, fire BN_CLICK event, and do everything else as "normal" buttons do. The unusual shapes produced by using  windows regions. Regions have been introduced in Windows 95, so do not try do use CUniButton on Win 3.1.  You can create button out of any shape you can think of.

CUniButton class was built on top of MFC CButton class.  Four bitmaps for NORMAL, SELECTED, HOVER, and DISABLE states are created in the constructor. Button responds to MOUSE OVER event and has separate background color for every button state. Region occupied by the button is specified in the constructor. When there is time to paint button one of the prepared bitmaps is painted.  Application of button region for clipping provides flicker free drawing.

I will list several topics covered in the CUniButton class:

  • creating and manipulating regions
  • SetWindowRgn()
  • GetWindowRgn()
  • PtInRegion()
  • SelectClipRgn()
  • GetRgnData()
  • mouse event handling, mouse capture
  • off screen bitmaps and DC's
  • BeginPath(), EndPath(), PathToRgn()
  • drawing 3D border around region
  • manipulation of region pixels
  • button inside of another button

Please look at source code to learn great potential of regions!



Download demo project - 46 KB

Date Last Updated: February 3, 1999



Comments

  • How can I Implement it in C# Project

    Posted by Legacy on 11/17/2003 12:00am

    Originally posted by: Darsi

    I want to Implement the UniButton in my C# project.
    Is there any code available directly for that.
    If it is, provide me the code and the method (or) procedure to implement it.

    Reply
  • Text buttons not working

    Posted by Legacy on 07/04/2003 12:00am

    Originally posted by: Varun

    The shape of the text buttons is showing as square instead of $ or @ in my project what might be the problem.

    I have copied UniButton.h & UniButton.cpp to my project, other than text buttons, all buttons are working fine help me plz.

    Reply
  • how to disable a button from another class

    Posted by Legacy on 03/31/2003 12:00am

    Originally posted by: gopikrishnan

    sir,
    I have a class named "BasicPanel which extends Jpanel" and main class "JsampleFrame which extends JFrame".Inside JsampleFrame class, i ve called the constructor
    "BasicPanel()" and added to the "Container".After that, i have created two buttons,where one button is disabled and other one enabled by default.
    My problem is that, once the user clicks the "checkbox" inside the panel of "BasicPanel",the button should get enabled.
    Please help to solve out this problem.

    Reply
  • Explanation?

    Posted by Legacy on 03/21/2003 12:00am

    Originally posted by: menime

    How does all of this work? Can someone explain to me the reason for all the procedures?

    Reply
  • Mine don't work...

    Posted by Legacy on 03/13/2003 12:00am

    Originally posted by: EvilsDawn

    I tried to create my own, simpler version of "UniButton"...derived a class from CButton, then overrode the afx_msg int OnCreate function...did the SetWindowRgn in there, but somehow, the button don't work...I try to look at the source code from the author, but I'm kinda confused...Can any of you help this loser ( aka me...:) )?

    Thx, ppl...

    Reply
  • Is it possible to use bitmap instead of a character?

    Posted by Legacy on 03/03/2003 12:00am

    Originally posted by: CENGIZ

    Cool.

    But I want to try a transparent bitmap in this topic. Instead of any of the characters as $ or @, I want to use a bitmap.

    Would you please give me an idea about it?

    Reply
  • Steef's question

    Posted by Legacy on 10/02/2002 12:00am

    Originally posted by: Stephan Deckers

    I've tried to use your button-login in an ActiveX control. The control is a button-based control, and I've set up the Window-region region in the OnCreate message handler, but when the OnDraw handler is called, the region is lost. Any ideas ?

    Reply
  • Problem w/hover color

    Posted by Legacy on 08/01/2002 12:00am

    Originally posted by: John Rossini

    I've found this control works really great. I've just had 1 problem with it. I'm using several buttons, each spawns a different program when the user hits the button. I found that the hover color of the button would remain after I spawned a program. It didn't matter how much I moved the mouse, or if I hit another button.
    I do have a solution, I don't think its the most elegant, but it seems to work. I add the function OnMouseMove() to my dialog, and in it I call OnMouseMove() for each of my buttons.
    If someone has a more elegant solution, I would be most interested in hearing it.

    John Rossini.

    Reply
  • Solution for changing the caption using SetWindowText

    Posted by Legacy on 02/21/2002 12:00am

    Originally posted by: Corneliu I. Tusnea

    Hi,
    
    

    Here is an answer for your question from CodeGuru about the caption of the UniButton

    Here is how to change the caption:
    Add the following function to the UniButton class

    LRESULT CUniButton::OnSetText(WPARAM, LPARAM newName)
    {
    m_bNeedBitmaps = true;
    Invalidate(TRUE);
    return Default();
    }

    And this to the msghadler
    ON_MESSAGE( WM_SETTEXT, OnSetText )

    Now you can change the caption using the SetWindowText ( .. )

    Good Luck,
    Tutu.

    Reply
  • How to change the button text dynamically, SetWindowText() not quite working

    Posted by Legacy on 02/05/2002 12:00am

    Originally posted by: Amit Gupta

    Dear Mr. Simakov:

    I recently downloaded your project utilising the CUnibutton class. The code is really excellent. Thank you.

    However I am having a "small" problem which has been haunting me since two days now. I know you would be able to help. The problem is that I want to change the window caption during runtime. I am trying to use SetWindowText for each button. It is not working, in the sense that although the text on the button changes in the memory, on the screen I still see the old text.

    Pleeeeeeeease help. Any suggestion, even a guess from your side will be more than welcome.

    Eagerly waiting

    Amit Gupta
    New Delhi, India

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds