XGlyphButton is a general-purpose button control that allows you to use images on the button without needing an ownerdraw control. With XGlyphButton, you can display any glyph from any installed font (for example, WingDings).
XGlyphButton addresses two problems with using images on buttons:
- When using themes on Windows XP, ownerdraw buttons will be drawn without the themed look.
- Bitmap buttons require use of multiple bitmaps and are overly complicated - especially when all you want to display is something simple like up or down arrows.
I wish to acknowledge the work of Geno Carman, whose article Create a Simple Image Button is what I based XGlyphButton on.
In using Carman's button class, I noticed that some glyphs were drawn with very ragged outlines. After some experimentation with GDI+ and other approaches, I came across
CLEARTYPE_QUALITY, which is one of the values for the
lfQuality element in the
struct. Here is what MSDN says about
Windows XP: If set, text is rendered (when possible) using ClearType antialiasing method.
On XP, for most of the glyphs in the WingDings and Symbol fonts, there is a very noticeable improvement when using
CLEARTYPE_QUALITY. On other systems such as Win98 (which do not have ClearType technology), the glyphs are displayed as usual.
In summary, if you can find a glyph in an installed font that is close to the image you want to display, then using XGlyphButton may save you some time, and will produce good-looking results on XP. The drawbacks:
- You are limited to the glyphs in the installed fonts.
- There is no way to change the text color, since you must do an ownerdraw button for that.
Here is what XGlyphButton buttons look like:
Here is the complete list of
void SetCharSet(BYTE bCharSet);
void SetFaceName(LPCTSTR lpszFaceName);
void SetFont(LOGFONT* plf);
void SetFont(CFont* pFont);
void SetGlyph(UINT cGlyph);
void SetGlyph(LOGFONT* plf, UINT cGlyph);
void SetGlyph(CFont* pFont, UINT cGlyph);
void SetGlyph(LONG lHeight, LONG lPointSize, LONG lWeight,
LPCTSTR lpszFaceName, UINT cGlyph);
void SetGlyph(LONG lPointSize, LPCTSTR lpszFaceName, UINT cGlyph);
void SetHeight(LONG lHeight);
void SetPointSize(LONG lPointSize);
void SetWeight(LONG lWeight);
void SetWingDingButton(UINT nButton);
How To Use
To integrate XGlyphButton into your app, you first need to add the following files to your project:
Then use the resource editor to add a button to your dialog, and use Class Wizard to attach a member variable to that control.
Next, include the header file XGlyphButton.h in the dialog's header file. Then replace the
CButton definition with
CXGlyphButton. Now you are ready to start using XGlyphButton.
Version 1.1 - 2004 March 10
This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.