Solved

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

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…

807 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