?
Solved

CListCtrl

Posted on 2009-05-05
2
Medium Priority
?
541 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
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.

719 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