Cool Font selection combo
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.
- Copy "FontCombo.h" and "TipWnd.h" to your project directory.
- Add the files to your project.
- Copy the "Printer.bmp" to your project "res" directory.
- #include "FontCombo.h" and "TipWnd.h" to the header file of your dialog class or to the "stdafx.h"
- Using the resource studio Import the printer.bmp and name it IDB_GLYPHS
- Using the dialog editor create your combo box and give it the following styles: "DropDown", Fixed, "Has Strings", and Verticle Scroll .
- Edit the dialogs class header file replace "CComboBox" for CFontCombo
- In OnInitDialog before the return statement Add the following line
m_yourCombo.SubclassDlgItem(IDC_COMBOID,this);
m_yourCombo.Initialize();

Files and resources needed to be included into you own project:
FontCombo.h & cpp
TipWnd.h & cpp,
IDB_GLYPH bitmap resource

Comments
Bug when scrolling with arrow key
Posted by Legacy on 02/08/2002 12:00amOriginally 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.
ReplyHow to make it work on a toolbar?
Posted by Legacy on 01/01/2000 12:00amOriginally 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
Replyrama_1000@yahoo.com
bug: scrolling listbox while tooltip is up
Posted by Legacy on 02/18/1999 12:00amOriginally posted by: Sean
Replya couple more mods
Posted by Legacy on 02/17/1999 12:00amOriginally posted by: Sean
Replyvoid CTipWnd::OnPaint()
Posted by Legacy on 10/19/1998 12:00amOriginally 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