Click here to Skip to main content
Click here to Skip to main content

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.

Introduction

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.

Demo

Here is what XGlyphButton buttons look like:

screenshot

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.

Usage

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.

License

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 www.hdsoft.org.






Comments and Discussions

 
Bugwingdings broken for unicode builds Pinmemberumeca7423-Mar-14 21:30 
GeneralI can't show correct icon on the button! Pinmemberdaveice4-Apr-05 20:27 
GeneralRe: I can't show correct icon on the button! PinmemberHans Dietrich6-Apr-05 8:41 
GeneralRe: I can't show correct icon on the button! Pinmemberdaveice6-Apr-05 17:35 
GeneralRe: I can't show correct icon on the button! PinmemberHans Dietrich8-Apr-05 6:48 
GeneralRe: I can't show correct icon on the button! Pinmemberdaveice8-Apr-05 18:58 
GeneralMaybe a badly designed XP theme? [modified] Pinmemberdgendreau13-Jun-06 8:19 
GeneralRe: I can't show correct icon on the button! Pinmembertom.schultz22-May-05 19:54 
GeneralRe: I can't show correct icon on the button! Pinmemberdaveice22-May-05 21:37 
GeneralComponent Gallery PinmemberRancidCrabtree22-Mar-04 12:34 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 10 Mar 2004
Article Copyright 2004 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid