Solved

Setting Font on CListCtrl

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

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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

21 Experts available now in Live!

Get 1:1 Help Now