Click here to Skip to main content
13,862,201 members
Click here to Skip to main content
Add your own
alternative version


77 bookmarked
Posted 9 Mar 2004
Licenced CPOL

XGlyphButton - a simple image button control

, 9 Mar 2004
Rate this:
Please Sign up or sign in to vote.
XGlyphButton is a simple CButton-based control that allows you to display an image without the need for owner-draw control.


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:

  1. When using themes on Windows XP, ownerdraw buttons will be drawn without the themed look.
  2. 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 LOGFONT struct. Here is what MSDN says about CLEARTYPE_QUALITY:

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:


XGlyphButton API

Here is the complete list of CXGlyphButton methods:

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:

  • XGlyphButton.cpp
  • XGlyphButton.h

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.

Revision History

Version 1.1 - 2004 March 10

  • Initial public release.


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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see

You may also be interested in...


Comments and Discussions

Bugwingdings broken for unicode builds Pin
umeca7423-Mar-14 22:30
memberumeca7423-Mar-14 22:30 
GeneralI can't show correct icon on the button! Pin
daveice4-Apr-05 21:27
memberdaveice4-Apr-05 21:27 
GeneralRe: I can't show correct icon on the button! Pin
Hans Dietrich6-Apr-05 9:41
mentorHans Dietrich6-Apr-05 9:41 
GeneralRe: I can't show correct icon on the button! Pin
daveice6-Apr-05 18:35
memberdaveice6-Apr-05 18:35 
GeneralRe: I can't show correct icon on the button! Pin
Hans Dietrich8-Apr-05 7:48
mentorHans Dietrich8-Apr-05 7:48 
GeneralRe: I can't show correct icon on the button! Pin
daveice8-Apr-05 19:58
memberdaveice8-Apr-05 19:58 
GeneralMaybe a badly designed XP theme? [modified] Pin
dgendreau13-Jun-06 9:19
memberdgendreau13-Jun-06 9:19 
GeneralRe: I can't show correct icon on the button! Pin
tom.schultz22-May-05 20:54
membertom.schultz22-May-05 20:54 
GeneralRe: I can't show correct icon on the button! Pin
daveice22-May-05 22:37
memberdaveice22-May-05 22:37 
GeneralComponent Gallery Pin
RancidCrabtree22-Mar-04 13:34
memberRancidCrabtree22-Mar-04 13:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190214.1 | Last Updated 10 Mar 2004
Article Copyright 2004 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid