Universal Button - beauty of HRGN | CodeGuru

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.  […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 3, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.