Link to home
Start Free TrialLog in
Avatar of winkle
winkle

asked on

Setting Font on CListCtrl

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
Avatar of Tommy Hui
Tommy Hui

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.
Avatar of winkle

ASKER

I deleted that line of code, The list still is not set to the Courier font.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial