Cool Font selection combo


Application Security Testing: An Integral Part of DevOps

This article was contributed by Norm Almond of Paramax Technology Limited

I came accross a fancy font selection box the other day. It was so cool I thought I'd copy the idea.

Its basically an imitation of the font selection box found in MS Word, it has an MRU font list and the other cool feature is that it has a Tooltip window showing the currently selected font name displayed using the selected font. This gives the user a sample of what the font is going to look like without actually making a selection.

The main component is an ownerdraw combo with has strings flags set, the combo isn't sorted because the Most Recently Used font are at  the top of the combo.

The combo is called CFontCombo it is simple to use in dialog boxes, just follow this simple instructions.

  1. Copy "FontCombo.h" and "TipWnd.h" to your project directory.
  2. Add the files to your project.
  3. Copy the "Printer.bmp" to your project "res" directory.
  4. #include "FontCombo.h" and "TipWnd.h" to the header file of your dialog class or to the "stdafx.h"
  5. Using the resource studio Import the printer.bmp and name it IDB_GLYPHS
  6. Using the dialog editor create your combo box and give it the following styles: "DropDown", Fixed, "Has Strings", and Verticle Scroll .
  7. Edit the dialogs class header file replace "CComboBox" for CFontCombo
  8. In OnInitDialog before the return statement Add the following line



fontcombo.gif (5338 bytes)

Files and resources needed to be included into you own project:

FontCombo.h & cpp

TipWnd.h & cpp,

IDB_GLYPH bitmap resource

Download Source Code


  • Bug when scrolling with arrow key

    Posted by Legacy on 02/08/2002 12:00am

    Originally posted by: St�phane Hamel

    If you use the arrow key to scroll in the dropdown list, the cursor jumps every time OnTimer is called.

  • How to make it work on a toolbar?

    Posted by Legacy on 01/01/2000 12:00am

    Originally posted by: Rama

    The code given here is used in a combo box on a dialog box.
    I tried to implement the same on a combo box placed on a toolbar for selecting the font (like the Wordpad or MS Word programs). However, somehow it did not succeed. Can anybocy suggest a way out? Thanks in advance.


  • bug: scrolling listbox while tooltip is up

    Posted by Legacy on 02/18/1999 12:00am

    Originally posted by: Sean

    In FontCombo.cpp

    Change the timer code so that it only repaints the tooltip if the
    selected item is visible in the listbox.

    void CFontCombo::OnTimer(UINT nIDEvent)
    // Is combo open
    if (GetDroppedState( ))
    int nSel = GetCurSel();
    int FirstVis = GetTopIndex();

    // Selected
    if (nSel != -1 && FirstVis <= nSel)
    CRect rc;
    int itemHeight = GetItemHeight(0);
    int lastVis = FirstVis + ((rc.Height()-itemHeight)/itemHeight);
    if (nSel <= lastVis)
    int nHeight = itemHeight * ((nSel - FirstVis) + 1);

    CPoint pt(rc.right + 5,rc.top + nHeight);

    // Show tip in correct position
    CString str;

  • a couple more mods

    Posted by Legacy on 02/17/1999 12:00am

    Originally posted by: Sean

    From TipWnd.cpp

    If using the infotip background, why not the foreground too?

    void CTipWnd::OnPaint()
    CPaintDC dc(this); // device context for painting

    CRect rc;
    dc.SetBkMode(TRANSPARENT); // Add
    dc.SetTextColor(GetSysColor(COLOR_INFOTEXT)); // Add
    // Do not call CWnd::OnPaint() for painting messages

    In FontCombo.cpp

    I changed all instances of ANSI_CHARSET to DEFAULT_CHARSET.
    I also removed the early returns in the 2 Callback fns.
    These changes result in a font list with contents more similar to
    the one I get in the MSDev Tools|Options|Format tab.

  • void CTipWnd::OnPaint()

    Posted by Legacy on 10/19/1998 12:00am

    Originally posted by: Akihiro Shamoto

    Modify this function...

    // from TipWnd.cpp
    void CTipWnd::OnPaint()
    CPaintDC dc(this); // device context for painting

    CRect rc;
    dc.SetBkMode(TRANSPARENT); // Add!!
    // Do not call CWnd::OnPaint() for painting messages

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.