🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How to get current LOGFONT

#2089
From: Alan Bellingham
Date: Tue, 01 May 2007 16:47
52 lines
2597 bytes
"Renald Yazmir" <renald@partmaker.com> wrote:

>1) How can I get current LOGFONT?
>
>I want to inquire the current font without displaying any dialog and without 
>asking to select the font.

Use GetObject() on an HFONT handle. Check the documentation for this. To
get the current font HFONT, if you've never actually selected one,
you'll probably find that GetStockObject() with a suitable parameter
does the job. Or perhaps the WM_GETFONT message will work.

>2) If I want to rotate the text can I set only sub set of LOGFONT 
>parameters. For example:
>
> log_font.lfHeight = font_height;
> log_font.lfWeight = FW_SEMIBOLD;
> log_font.lfEscapement = (LONG_T)(angle*10);
>...
>
> hfnt = CreateFontIndirect(&log_font);

Surely.

>Do I need to worry about the rest of parameters or I can just call:
>
> memset(&log_font, 0, sizeof(LOGFONT));

If you do, you'll get defaults for all the other values. This may or may
not be what you want.

BTW, it's often considered good practice to avoid memset() when it's not
necessary. In this case

 LOGFONT log_font = { 0 };
 log_font.lfHeight = font_height;
 log_font.lfWeight = FW_SEMIBOLD;
 log_font.lfEscapement = (LONG_T)(angle*10);

would do fine. On the other hand, given you've been asking about getting
the current font details, then something like (untested)

 LOGFONT log_font = { 0 };
 HFONT Font = reinterpret_cast<::SendMessage(hWnd, WM_GETFONT, 0, 0));
 GetObject(HFont, sizeof log_font, &log_font);
 log_font.lfEscapement = (LONG_T)(angle*10);

looks like the right way to go.

Alan Bellingham
-- 
ACCU Conference 2008: 2-5 April 2008 - Oxford (probably), UK
Technical Details
Message-ID: <j3re33h1eo7c260b81sd237hv17fpg0846@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <46376b43$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,812e79cdc65370e5
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Alan Bellingham <alan@lspace.org>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: How to get current LOGFONT
Date: Tue, 01 May 2007 17:47:46 +0100
Organization: Private
Reply-To: alan@lspace.org
Message-ID: <j3re33h1eo7c260b81sd237hv17fpg0846@4ax.com>
References: <46376b43$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 4.2/32.1118
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 193.129.251.253
X-Trace: newsgroups.borland.com 1178038065 193.129.251.253 (1 May 2007 09:47:45 -0700)
Lines: 52
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail