Page 1 of 1

Size of text in a Form caption

Posted: Thu Sep 03, 2015 9:44 am
by kai
I want to take into account the size of the caption of a Form when calculating the best size of a Form dynamically.

Ideally I would use the GetTextSize function but naturally that won't work. I don't want to use a .NET call, and I don't want to make just assumptions of what the font used by Windows might actually be.

Any ideas?

Re: Size of text in a Form caption

Posted: Thu Sep 03, 2015 3:47 pm
by ray
Hi Kai

The Windows API function GetSystemMetrics will give you a lot of information that you might find useful.

In this old function (pre 2000) I used it to find the size of the scroll bars but GetSystemMetrics contains a lot more useful stuff.

      SetPW;old;wid;sw;GET;sb;pw;fn16;cursz;dll;⎕IO;⎕ML
⍝ ---Set ⎕PW according to APL font size and Screen dimensions
⎕IO←1 ⋄ ⎕ML←0 ⍝
old←'⎕se'⎕WG'coord' ⍝ Save current coord system
'⎕se'⎕WS'coord' 'pixel' ⍝ Set Coord system to PIXEL
wid←2⊃'⎕se'⎕WG⊂'Textsize' '⎕' ⍝ Get size of an APL character
cursz←2⊃'⎕se'⎕WG'Size'
'⎕se'⎕WS'coord'old
dll←'user32|GetSystemMetrics'
'fn16'⎕NA'I ',dll,' I'
sw←cursz-fn16 2 ⍝ Screen width, reduce by scroll bar width
pw←30⌈⌊sw÷wid ⍝ calculate width in APL char units
⎕PW←pw ⍝ Set Page Width


Hope this might help, or give you ideas.

Ray

Re: Size of text in a Form caption

Posted: Fri Sep 04, 2015 3:34 pm
by kai
Ray, thanks for that.

I am fully aware of GetSystemMetrics. I can find out everything except ... <drumroll> ... the size of the caption and the font used by the operating system!

Re: Size of text in a Form caption

Posted: Fri Sep 04, 2015 7:51 pm
by PGilbert
Hello Kai, are looking at finding the size and name of the font used for example in the 'Active Title Bar' as show below ?:

Re: Size of text in a Form caption

Posted: Sun Sep 06, 2015 3:31 pm
by gil
Kai, I don't know if there's an elegant way, but have you tried the registry?

See the entries under:

HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics

Re: Size of text in a Form caption

Posted: Mon Sep 07, 2015 8:02 am
by Veli-Matti
Hi,
perhaps I'm on the wrong track, but if you are just looking for the Caption size, the Metrics helps a bit:

      {∆m←+⋄(⎕EX'∆m')⊢∆m ⍵⊣'∆m'⎕NA'I4 User32|GetSystemMetrics I4'}4
22

(4 represents here SM_CYCAPTION, the height of a caption area, in pixels)

-Veli-Matti

Re: Size of text in a Form caption

Posted: Tue Sep 08, 2015 8:08 pm
by PGilbert
Hello Kai, I know you said no .Net but I could not resist:

      ⎕using←'System.Windows,WPF/PresentationFramework.dll'
SystemFonts.CaptionFontSize
12
SystemFonts.CaptionFontFamily
Segoe UI