Solved

How to change font size in CComboBox?

Posted on 1998-10-12
1
1,668 Views
Last Modified: 2013-12-03
How to change font size in CComboBox and CListBox?
0
Comment
Question by:Nightmare090197
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1323220
Send a WM_SETFONT message to the control.  this contains an HFONT of the font you want to use and a flag indicating if you want to redraw the control.

Steps

1. Associate a CComboBox or CListBox class with the control you want (e.g. use class wiz for dialog apps) - e.g. m_combo for CComboBox, or m_list for CListBox.

2. Use SendMessage to send the message.  If the control is on a dialog, and font doesn't change, then OnInitDialog is a good place to do this

m_combo.SendMessage( WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE,0) ) ; // FALSE instead of TRUE if you don't want immediate redraw

m_list.SendMessage( WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE,0) ) ; // FALSE instead of TRUE if you don't want immediate redraw

3. You can get the hFont a couple of ways

i. Use a stock font, in which case you do not need to clear up
hFont = (HFONT)::GetStockObject( SYSTEM_FIXED_FONT ) ;

or

ii. Create your own font.  In this case you need to clear up, set the font back before your dialog exits, and make sure any fonts you create are also deleted.

You create fonts using CreateFont or CreateFontIndirect.
You delete fonts using DeleteFont

Example:
    (a) Add member variable HFONT m_hOldFont to your dialog class
    (b) Add member variable HFONT m_hFont to your dialog class
    (c) In OnInitDialog you can create the font, based on a new LOGFONT that you supply, or by getting the current values

   m_hOldFont = (HFONT)m_list.SendMessage( WM_GETFONT, 0, 0 ) ;
   LOGFONT lf ;
   ::GetObject( (HGDIOBJ)m_hOldFont, sizeof lf, &lf ) ;
   lf.lfHeight = 32 ; // some new size
   m_hFont = ::CreateFontIndirect( &lf ) ;
   m_list.SendMessage( WM_SETFONT, (WPARAM)m_hFont, MAKELPARAM(TRUE,0) ) ;
   m_combo.SendMessage( WM_SETFONT, (WPARAM)m_hFont, MAKELPARAM(TRUE,0) ) ;

   (d) When destroy the dialog (e.g. OnOK) set font back, and delete the font you created
   m_list.SendMessage( WM_SETFONT, (WPARAM)m_hOldFont, MAKELPARAM(TRUE,0) ) ;
   m_combo.SendMessage( WM_SETFONT, (WPARAM)m_hOldFont, MAKELPARAM(TRUE,0) ) ;
   ::DeleteObject( m_hFont ) ;

   

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 382
Font install problem 9 50
modThree challenge 4 96
How to install a font on WIN2003SBS/IIS 6 & test 17 32
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question