Solved

CListCtrl

Posted on 2009-05-05
2
539 Views
Last Modified: 2013-12-14
Hi,
I am trying to change the font size in the Header of the a CListCtrl control.
I did as in the attached code but it did not work.
The font just became like a SYSTEM font.

CHeaderCtrl *header=list.GetHeaderCtrl( );
 HWND hwnd=header->GetSafeHwnd();
	HDC  hDC=::GetDC(hwnd);
	
	CFont font;
	LOGFONT lf;
	memset(&lf, 0, sizeof(LOGFONT));        zero out structure
	lf.lfHeight = 6;                       request a 12-pixel-height font
	strcpy(lf.lfFaceName, "Arial Narrow");         request a face name "Arial"
	VERIFY(font.CreateFontIndirect(&lf));   create the font
	
	header->SetFont( &font); 
	
	::SelectObject( hDC, (HFONT) font);
	::ReleaseDC(hwnd,hDC);

Open in new window

0
Comment
Question by:VapiSoft
[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
2 Comments
 
LVL 19

Expert Comment

by:alb66
ID: 24311704
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 24322837
CHeaderCtrl *header=list.GetHeaderCtrl( );
 HWND hwnd=header->GetSafeHwnd();
        HDC  hDC=::GetDC(hwnd);
       
        CFont font;                <<<---------------------------------------------------------- LOCAL
        LOGFONT lf;
        memset(&lf, 0, sizeof(LOGFONT));        zero out structure
        lf.lfHeight = 6;                       request a 12-pixel-height font
        strcpy(lf.lfFaceName, "Arial Narrow");         request a face name "Arial"
        VERIFY(font.CreateFontIndirect(&lf));   create the font
       
        header->SetFont( &font);
       
        ::SelectObject( hDC, (HFONT) font);
        ::ReleaseDC(hwnd,hDC);

You create a font local to the function, attach to the header then when the function exits the font is DESTROYED.
Solution - the CFont must be declared at the class scope (in the .h file)
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

617 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