?
Solved

read Windows Font Size

Posted on 1997-08-14
6
Medium Priority
?
388 Views
Last Modified: 2013-12-02
In a Delphi program I display text from a textfile, with
a specifiable font size on a window.
The problem off course is, that when someone on the network
has changed his
Start->Settings->Control Panel->Display->Setting->Font Size
setting to Large fonts, he can't read all of the text.

My question is:

  How can I determiner this setting in delphi (remember
  a Windows APi call, but I can get the use of parameters
  right, so please give a example procedure).

  How can I map these large fonts to small fonts
  ,calculate the font size to use (
  I mean I want the person with the large fonts settings
  to see the same size of the text in my programwindow,
  he would see if you used the small fonts settings).
  Can I just divide a certain font size by half?
  Is this a constant?

 
0
Comment
Question by:mosi
[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
6 Comments
 
LVL 3

Expert Comment

by:mirek071497
ID: 1341420
Can't you use TFont.size property for calculating You'r display ?
When text is (in example) in TMemo then user can use ScrollBars so tell more what happened and what you need because i can't understand.
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1341421
You want the text metrics for the font.

VAR
  DC: HDC;
  SaveFont: HFont;
  Metrics: TTextMetric;
 

DC := GetDC(0);
SaveFont := SelectObject( DC, Font.Handle);
GetTextMetrics(DC, Metrics );
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);

Now, you have use of the metrics, like:

MyHeight := Metrics.tmHeight + 3;

Hope this helps.

Ian C.

0
 
LVL 1

Author Comment

by:mosi
ID: 1341422

Thanx ICAMPBEL, but I rejected your answer, althrough it probably contains part of the answer, but it is not so complete that I can use it. Please clarify!

I tried your code, and when Windows 95 on this PC  is using The large font setting, I get a Metrics.tmHeight value of 16. When it is using
The small font setting, I get a Metrics.tmHeight value of 13.
Will this always be the case, on all PC's, not depending on other
settings such as resolution e.g. 1024*768 in stead of 800 * 600, or other videodrivers?

I explain again what I what to do (simplified):

I display a window on the screen which always has a width of 600 pixels.
In this window is a label. The program reads the text to display on this
label and it fontsize from the commandline.
Suppose, I have a text to display which exactly fits into that window,
when I'm using the Use small fonts setting in Windows 95, only
a part will be visible when I'm using the Use large fonts settings.
(I do not want  use scrolling),

Therefore I need a function like this;

FontSizeFromCommandline (integer) is known, e.g. 14

FontSizeToUse:= CalculateFontSizeToUse(FontSizeFromCommandline);

CalculatieFontSizeToUse must do 2 things.

 1) Detect whether the Windows 95/NT setting of the fonts to use
    is Use Large Fonts or Use Small Fonts

 2a) When the setting is Use Small Fonts: return     FontSizeFromCommandline
    (in fact: do nothing, this value is already known).
   
 2b) When the setting is Use Large Fonts: calculate a fontsize,
    depending on FontSizeFromCommandline, such that exactly the
    same text will fit onto (the same line on) the window, as if the
    setting would be Use Small Fonts.













 
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:mosi
ID: 1341423
Adjusted points to 110
0
 
LVL 1

Accepted Solution

by:
jackb022197 earned 440 total points
ID: 1341424
Use the GetSysFont function from the following unit to determine the 6 designated system font:

{ ------------------------------------------------------------------------- }
{ Description:                                                              }
{    Retrieves fonts assigned to the system screen elements.                }
{                                                                           }
{ Declaration:                                                              }
{    Function GetSysFont(FontParam: TSysFont; var ResFont: TFont): Boolean; }
{                                                                           }
{ Parameters:                                                               }
{    FontParam - Enumerated type that specifies the system font to          }
{    retrieve. This is one of the following values: sfCaptionFont,          }
{    sfSmCaptionFont, sfMenuFont, sfStatusFont, sfMessageFont, sfIconFont.  }
{                                                                           }
{    ResFont - A TFont variable that can be used to store the resulting     }
{    TFont object.                                                          }
{ ------------------------------------------------------------------------- }
unit SysFont;

interface

Uses
      SysUtils, Windows, Graphics;

type
       TSysFont = (sfCaptionFont, sfSmCaptionFont, sfMenuFont,
                  sfStatusFont, sfMessageFont, sfIconFont);


Function GetSysFont(FontParam: TSysFont; var ResFont: TFont): Boolean;
procedure TFontFromLogFont(const LogFont: TLogFont; var NewFont: TFont);

implementation

{ Gets the System font setting of the passed TSysFont parameter }
Function GetSysFont(FontParam: TSysFont; var ResFont: TFont): Boolean;
var
      TempNonClientMetrics: TNonClientMetrics;
      TempLogFont: TLogFont;
      ret: boolean;
begin
      Result := false;
      If FontParam = sfIconFont then
            { The IconFont is retreived with a different method
                  than all the other system fonts }
            ret := SystemParametersInfo(SPI_GETICONTITLELOGFONT,
                        SizeOf(TempLogFont), @TempLogFont, 0)
      else
            begin
                  TempNonClientMetrics.cbSize := SizeOf(TempNonClientMetrics);
                  ret := SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0,
                              @TempNonClientMetrics, 0);
            end;

      { If call to SystemParametersInfo() not successful then exit}
      If not ret then exit;

      { Load appropriate TempNonClientMetrics field into TempLogFont }
      case FontParam of
            sfCaptionFont:
                  TempLogFont := TempNonClientMetrics.lfCaptionFont;
            sfSmCaptionFont:
                  TempLogFont := TempNonClientMetrics.lfSmCaptionFont;
            sfMenuFont:
                  TempLogFont := TempNonClientMetrics.lfMenuFont;
            sfStatusFont:
                  TempLogFont := TempNonClientMetrics.lfStatusFont;
            sfMessageFont:
                  TempLogFont := TempNonClientMetrics.lfMessageFont;
      end;

      { Convert TempLogFont into a TFont }
      TFontFromLogFont(TempLogFont, ResFont);
      Result := true;
end;

{ Converts a LogFont structure to a Delphi TFont }
procedure TFontFromLogFont(const LogFont: TLogFont; var NewFont: TFont);
var
      Style: TFontStyles;
begin
      with LogFont do
      begin
            NewFont.Name := lfFaceName;
            NewFont.Height := lfHeight;
            Style := [];

            if lfWeight > FW_REGULAR then Include(Style, fsBold);
            if lfItalic <> 0 then Include(Style, fsItalic);
            if lfUnderline <> 0 then Include(Style, fsUnderline);
            if lfStrikeOut <> 0 then Include(Style, fsStrikeOut);

            NewFont.Style := Style;
      end;
end;

end.
0
 
LVL 1

Author Comment

by:mosi
ID: 1341425
Thanx.
I accept your answer, although I guess I still have to
work out some things.
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 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