Solved

changing the font of a win32 window and its child windows and controls

Posted on 2004-03-22
2
1,097 Views
Last Modified: 2013-12-03
Hi. I have a win32 window in my app created using CreateWindowEx. It is not a dialog and I am not using MFC. I want to be able to change the font of this window as well as all of its child windows and any controls that it has. I have read that you should be able to do this by creating your font using CreateFont, storing the result as an HFONT. Then send a WM_SETFONT message to the window. eg.
      SendMessage(m_hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));

where hFont is the desired font. However this seems to do nothing. I call this code after I have created the main window but before any children or controls have been created. If I call:

      SelectObject(GetDC(m_hWnd), hFont);

Then that seems to set the font for the device context of the window without a problem as I can do a TextOut inside the WM_PAINT message catch and text is written correctly in the desired format. I really want to get this sorted as I hate the bold font used by default with win32 controls etc. Thanks for any help.
0
Comment
Question by:BigBadBob
2 Comments
 
LVL 6

Expert Comment

by:PlanetCpp
ID: 10660653
i have an example of changing fonts on my site www.PlanetCpp.com in the source section it changes font and colors
0
 
LVL 1

Accepted Solution

by:
DunjinMaster earned 250 total points
ID: 10746599
I've been looking into this myself. Here's what you'll need to do:

1. Use CreateFont or CreateFontIndirect to create a local font handle.

Example:
 hCurrentFont := CreateFont(13, 0, 0,
    0, FW_REGULAR, 0, 0, 0,
    ANSI_CHARSET, OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS,
    PROOF_QUALITY, DEFAULT_PITCH, PAnsiChar('Tahoma'));

2. Send the font handle as the HPARAM part of a SendMessage call to send WM_SETFONT to the window's handle. Set the LPARAM high byte to true.

Example:
SendMessage(hWindow, WM_SETFONT, hCurrentFont, MAKELPARAM(1, 0));

3. Wonder at the simplicity and how little info there is on this. ;-)

My examples are Delphi's Pascal variant, but easily converted to C++.

Hope that helps!
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 39
Problem to DocumentFormat 8 95
Poor Man's .NET Framework Certification 2 59
windbg taking it's time 32 91
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

821 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