Size of text in a Form caption

Using (or providing) components based on the "Win32" framework

Size of text in a Form caption

Postby kai on Thu Sep 03, 2015 9:44 am

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?
User avatar
kai
 
Posts: 137
Joined: Thu Jun 18, 2009 5:10 pm
Location: Hillesheim / Germany

Re: Size of text in a Form caption

Postby ray on Thu Sep 03, 2015 3:47 pm

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
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: Size of text in a Form caption

Postby kai on Fri Sep 04, 2015 3:34 pm

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!
User avatar
kai
 
Posts: 137
Joined: Thu Jun 18, 2009 5:10 pm
Location: Hillesheim / Germany

Re: Size of text in a Form caption

Postby PGilbert on Fri Sep 04, 2015 7:51 pm

Hello Kai, are looking at finding the size and name of the font used for example in the 'Active Title Bar' as show below ?:
Attachments
Image1.png
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Size of text in a Form caption

Postby gil on Sun Sep 06, 2015 3:31 pm

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
gil
 
Posts: 71
Joined: Mon Feb 15, 2010 12:42 am

Re: Size of text in a Form caption

Postby Veli-Matti on Mon Sep 07, 2015 8:02 am

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
Veli-Matti
 
Posts: 93
Joined: Sat Nov 28, 2009 3:12 pm

Re: Size of text in a Form caption

Postby PGilbert on Tue Sep 08, 2015 8:08 pm

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
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada


Return to Windows: GUI, COM/OLE/ActiveX

Who is online

Users browsing this forum: No registered users and 1 guest