Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-03-22
2
Medium Priority
?
1,119 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 750 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

886 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