Solved

CListCtrl

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 74
vb.net - How to check if current user is an administrator? 6 73
eclipse apache tomcat admin console 52 191
Adjust the codes 3 63
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
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 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…

739 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