Solved

How to change font size in CComboBox?

Posted on 1998-10-12
1
1,706 Views
Last Modified: 2013-12-03
How to change font size in CComboBox and CListBox?
0
Comment
Question by:Nightmare090197
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How are Button Fonts Created? 2 61
x-bar in Google Sheets 2 129
Work with App store 7 122
Text effect for logo 17 64
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…

734 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