Virtual Developer Workshop: Containerized Development with Docker

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


  • How can I Implement it in C# Project

    Posted by Legacy on 11/17/2003 08: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.

  • Text buttons not working

    Posted by Legacy on 07/04/2003 07: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.

  • how to disable a button from another class

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

    Originally posted by: gopikrishnan

    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.

  • Explanation?

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

    Originally posted by: menime

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

  • Mine don't work...

    Posted by Legacy on 03/13/2003 08: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...

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

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

    Originally posted by: CENGIZ


    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?

  • Steef's question

    Posted by Legacy on 10/02/2002 07: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 ?

  • Problem w/hover color

    Posted by Legacy on 08/01/2002 07: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.

  • Solution for changing the caption using SetWindowText

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

    Originally posted by: Corneliu I. Tusnea


    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;
    return Default();

    And this to the msghadler

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

    Good Luck,

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

    Posted by Legacy on 02/05/2002 08: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

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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