Solved

Setting Font on CListCtrl

Posted on 1998-06-09
3
333 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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…

813 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

12 Experts available now in Live!

Get 1:1 Help Now