๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #10944

Re: Fontsettings

#10944
From: Ed Mulroy [TeamB]
Date: Sat, 06 Mar 2004 21:17
66 lines
2988 bytes
Something like this should be able create a font of a certain point size.

Note that if you've only the control ID then you can get the HWND it needs
with GetDlgItem(containing_hwnd, ID_NUMBER);

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

  bool InitFont(int font_pts)
    {
    LOGFONT lf;

    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: <404a3fd7$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!border1.nntp.ash.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <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 13:37:01 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 16:17:00 -0500
Lines: 68
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: <404a3fd7$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1078607831 24.74.175.102 (6 Mar 2004 13:17:11 -0800)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!border1.nntp.ash.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail