Solved

CListCtrl

Posted on 2009-05-05
2
520 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
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

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

914 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

13 Experts available now in Live!

Get 1:1 Help Now