Solved

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

Posted on 2004-03-22
2
1,088 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
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 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…

747 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

11 Experts available now in Live!

Get 1:1 Help Now