Solved

CListCtrl

Posted on 2009-05-05
2
518 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
Comment Utility
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

763 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

8 Experts available now in Live!

Get 1:1 Help Now