Jump to content

Detecting font size in an edit control


Recommended Posts

I'm looking for a way to reliably work out how many characters will fit into an edit control, using a monospaced font like Courier New.

; Create an edit control, 400x200 pixels
$handle = GUICtrlCreateEdit("", 0, 0, 400, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL, $WS_BORDER))

; Use monospaced Courier New font, size 9
GUICtrlSetFont($handle, 9, 400, 0, "Courier New")

; Display a message
_GUICtrlEdit_AppendText($handle, "Hello world!")

This code will create the edit control.

Alas, the font size of "9" doesn't tell me how many characters I can actually fit on each line (and how many lines I can fit in the control).

(Characters of this size are acutally 7 pixels wide and 15 pixels high.)

The solution I'm looking for is any of the following:

(1) A way to convert <font name> and <font size> into <font actual width> and <font actual height>

(2) A way to convert <window width in pixels> and <window height in pixels> into <max columns> and <max rows>

(3) Some web page that lists the actual sizes of standard Windows fonts

I've spent hours trying each solution in turn, with no success. Can anyone help?

Link to comment
Share on other sites

Forgive a n00b question: I know little about C/C#.

How can I call the MSDN function in the above link from within an AutoIt script?

Here's my best guess. The link says the function, GetTextExtentPoint32(), returns a "size structure".

That's meaningless to me, and the AutoIT help file for DllCall() doesn't specify that kind of data type, or how to deal with it.

$result = DllCall("Gdi32.dll", "size", "GetTextExtentPoint32", "str", "hello world")
Edited by annelinn
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...