Solved

Setting Font on CListCtrl

Posted on 1998-06-09
3
329 Views
Last Modified: 2013-12-03
I'm trying to set the font of a CListCtrl to be different from the other items in a dialog. This works when the program is run under Win 95, but when run under NT 4.0 the font is not changed. I have made sure that the font is in the system.

I'm using MSDEV C++ 5.0 on NT 4.0 &  Win 95. Here's a code snippet.


 CClientDC hDC(this);
  CFont listFont;
  int ptSize = 10;
  int ptsPerInch = 72;
 
  ::SetMapMode(hDC, MM_TEXT);
  int nHeight = -((hDC.GetDeviceCaps(LOGPIXELSY) * ptSize) / ptsPerInch);

  if ((HFONT) listFont != NULL) {
    listFont.DeleteObject();
  }
  BOOL aFontErr = listFont.CreateFont(nHeight, 0, 0, 0, FW_NORMAL,
                                      0, 0, 0, DEFAULT_CHARSET,
                                      OUT_TT_PRECIS, CLIP_TT_ALWAYS,
                                      DEFAULT_QUALITY, FF_ROMAN, "Courier New");
   
   ::SelectObject(hDC, (HFONT)listFont);
   m_myList.SetFont(&listFont);

On NT the CListCtrls
0
Comment
Question by:winkle
3 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1317808
You do not have to select the font into the DC in order to use SetFont. The selection of the font makes it automatically destroyed when the client DC goes out of scope. Ideally, you need to make sure the life time of the font is longer than or equal to the life time of that list control.
0
 

Author Comment

by:winkle
ID: 1317809
I deleted that line of code, The list still is not set to the Courier font.
0
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1317810
You should define listFont as a member variable just like m_myList. Or, the font object will be destroyed once the execution goes beyond the function.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…

762 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

28 Experts available now in Live!

Get 1:1 Help Now