Solved

Setting Font on CListCtrl

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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. …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 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