Solved

How to change font size in CComboBox?

Posted on 1998-10-12
1
1,620 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 106
Perl Awk Need Help 3 109
Generic progress indicator 6 113
Process filename extension 3 172
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now