Cool Font selection combo

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

    m_yourCombo.SubclassDlgItem(IDC_COMBOID,this);

    m_yourCombo.Initialize();

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



Comments

  • 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.

    Reply
  • 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.

    Rama
    rama_1000@yahoo.com

    Reply
  • 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;
    GetDroppedControlRect(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;
    GetLBText(nSel,str);
    m_wndTip.ShowTips(pt,str);
    }
    }
    }
    CComboBox::OnTimer(nIDEvent);
    }

    Reply
  • 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

    dc.SelectObject(&m_font);
    CRect rc;
    GetClientRect(rc);
    dc.SetBkMode(TRANSPARENT); // Add
    dc.SetTextColor(GetSysColor(COLOR_INFOTEXT)); // Add
    dc.DrawText(m_strFont,rc,DT_SINGLELINE|DT_VCENTER|DT_CENTER);
    // 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.

    Reply
  • 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

    dc.SelectObject(&m_font);
    CRect rc;
    GetClientRect(rc);
    dc.SetBkMode(TRANSPARENT); // Add!!
    dc.DrawText(m_strFont,rc,DT_SINGLELINE|DT_VCENTER|DT_CENTER);
    // Do not call CWnd::OnPaint() for painting messages
    }


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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Due to internal controls and regulations, the amount of long term archival data is increasing every year. Since magnetic tape does not need to be periodically operated or connected to a power source, there will be no data loss because of performance degradation due to the drive actuator. Read this white paper to learn about a series of tests that determined magnetic tape is a reliable long-term storage solution for up to 30 years.

Most Popular Programming Stories

More for Developers

RSS Feeds