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
- 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!
Date Last Updated: February 3, 1999