Software Secret Weapons™

UniButton – one of my earlier projects
by Pavel Simakov on 2012-12-06 20:31:33 under Uncategorized, view comments
Bookmark and Share

Just found one of my early day projects on CodeGuru. Written on December 26, 1998 - a very long time ago. There were the days of MFC and Visual Studio. I was experimenting with HRegion and came up with this UniButton project.

How much has changed in the world since then. But... the Windows binary still works! Here is the original post:

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!

No comments yet

Leave a comment

  Copyright © 2004-2015 by Pavel Simakov
any conclusions, recommendations, ideas, thoughts or the source code presented on this site are my own and do not reflect a official opinion of my current or past employers, partners or clients