Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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…
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…
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…

688 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