Article View: borland.public.cppbuilder.nativeapi
Article #10945Re: Fontsettings
From: Ed Mulroy [TeamB]
Date: Sat, 06 Mar 2004 23:38
Date: Sat, 06 Mar 2004 23:38
68 lines
2927 bytes
2927 bytes
Something like the code at the bottom should be able create a font of a
certain point size.
For TextOut use the SelectObject as Mr Gonder showed. For a listbox send it
a message telling it to use the font. Code to do that should look something
like this:
SendMessage(listbox_hwnd, WM_SETFONT,
reinterpret_cast<WPARAM>(font_hand), FALSE);
Note that if you've only the control ID then you can get the HWND it needs
with GetDlgItem(containing_hwnd, ID_NUMBER);
Also note that in Mr Gonder's example he has the font being created and then
deleted on each pass through the TextOut. You might consider doing it a bit
differently, creating the font when the program starts and deleting it when
the program ends.
. Ed
-------------------------
#include <windows.h>
// Create a fixed-width font of a given size in points
// Return the font handle (will be NULL if it couldn't create it)
// Call DeleteObject to delete the font handle
// at the end of the program
HFONT InitFont(int font_pts)
{
LOGFONT lf;
HFONT font_hand;
ZeroMemory(&lf, sizeof(lf));
lstrcpy(lf.lfFaceName, "Lucida Sans Typewriter Regular");
lf.lfWeight = FW_LIGHT;
HDC hdc = GetDC(GetDesktopWindow());
lf.lfHeight =
-MulDiv(font_pts, GetDeviceCaps(dc, LOGPIXELSY), 72);
ReleaseDC(hdc);
font_hand = CreateFontIndirect(&lf);
// if it couldn't find Lucida, try again with Courier New
if (!font_hand)
{
lstrcpy(lf.lfFaceName, "Courier New");
font_hand = CreateFontIndirect(&lf);
}
return font_hand;
}
-------------------------
> Johan Elms๏ฟฝter wrote in message
> news:4049d1af@newsgroups.borland.com...
>
> I have made a little application, with one button a bitmap, a
> listbox and I'm using the textout API to show some text in
> the window.
>
> Now I wonder how I set the fontsize for the text drawn with
> textout and the text added in the listbox.
>
> Does anyone know?
Technical Details
Message-ID:
<404a60f5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4049d1af@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10cc67,d1297fa599b5b2a3 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-03-06 15:39:34 PST From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Newsgroups: borland.public.cppbuilder.nativeapi References: <4049d1af@newsgroups.borland.com> Subject: Re: Fontsettings Date: Sat, 6 Mar 2004 18:38:18 -0500 Lines: 71 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 24.74.175.102 Message-ID: <404a60f5$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1078616309 24.74.175.102 (6 Mar 2004 15:38:29 -0800) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail