Sign in to follow this  
Followers 0
Melba23

Determining font family/size from font handle

3 posts in this topic

Hi,

I am trying to get my head around fonts - not an easy task as I am rapidly finding out! At this moment I am attempting to identify the font used in a control - something which Au3 Window Info does not give me - perhaps for a very good reason!

I have found that I can get the handle to the font in a control by using the following:

$hWnd = ControlGetHandle($hGui, "", $hControl)
$hFont = _SendMessage($hWnd, $WM_GETFONT, 0, 0, 5)

This returns a nice array:

[0] = 185211881

[1] = 0x000508F4

[2] = 49

[3] = 0

[4] = 0

which is all very well, but does not let me identify the font in question. I have looked through MSDN and Googled furiously and there does not appear to be function to get the font family/size data from this handle, although I have found a number of quotes such as:

"HFONT, a handle to a Logical Font in memory. The data held by this handle can be retrieved into a LOGFONT structure"

So to my question: How can you get the LOGFONT from the handle in AutoIt?

From my studies, I believe the LOGFONT structure should read:

$tLOGFONT = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]")

derived from:

typedef struct tagLOGFONT {

LONG lfHeight;

LONG lfWidth;

LONG lfEscapement;

LONG lfOrientation;

LONG lfWeight;

BYTE lfItalic;

BYTE lfUnderline;

BYTE lfStrikeOut;

BYTE lfCharSet;

BYTE lfOutPrecision;

BYTE lfClipPrecision;

BYTE lfQuality;

BYTE lfPitchAndFamily;

TCHAR lfFaceName[LF_FACESIZE];

} LOGFONT, *PLOGFONT;

But how to populate it, given the handle?

Grateful for any pointers (pun firmly intended!),

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

I am trying to get my head around fonts - not an easy task as I am rapidly finding out! At this moment I am attempting to identify the font used in a control - something which Au3 Window Info does not give me - perhaps for a very good reason!

I have found that I can get the handle to the font in a control by using the following:

$hWnd = ControlGetHandle($hGui, "", $hControl)
$hFont = _SendMessage($hWnd, $WM_GETFONT, 0, 0, 5)

This returns a nice array:

[0] = 185211881

[1] = 0x000508F4

[2] = 49

[3] = 0

[4] = 0

which is all very well, but does not let me identify the font in question. I have looked through MSDN and Googled furiously and there does not appear to be function to get the font family/size data from this handle, although I have found a number of quotes such as:

"HFONT, a handle to a Logical Font in memory. The data held by this handle can be retrieved into a LOGFONT structure"

So to my question: How can you get the LOGFONT from the handle in AutoIt?

From my studies, I believe the LOGFONT structure should read:

$tLOGFONT = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]")

derived from:

typedef struct tagLOGFONT {

LONG lfHeight;

LONG lfWidth;

LONG lfEscapement;

LONG lfOrientation;

LONG lfWeight;

BYTE lfItalic;

BYTE lfUnderline;

BYTE lfStrikeOut;

BYTE lfCharSet;

BYTE lfOutPrecision;

BYTE lfClipPrecision;

BYTE lfQuality;

BYTE lfPitchAndFamily;

TCHAR lfFaceName[LF_FACESIZE];

} LOGFONT, *PLOGFONT;

But how to populate it, given the handle?

Grateful for any pointers (pun firmly intended!),

M23

I don't know the answer but my guess is that you need to create a logfont structure, get the lofgont handle using

$hLogFont = _SendMessage($hWnd, $WM_GETFONT, 0, 0)

then get the data into the structure using $hLogFont in _WinAPI_GetObject twice, first with the first parameter as 0 to get the number of bytes needed, then use that for the second parameter the second time. So it would be something like this

$hLogFont = _SendMessage($hWnd, $WM_GETFONT, 0, 0)
$structLF = DllStructCreate($tagLogFont)
$isize = _WinAPI_GetObject($hLogFont ,0,0)
$iWritten = _WinAPI_GetObject($hLogFont ,$isize,DllStructGetptr($structLF))

then the data should be in the struct for you to read.

I haven't tried it btw.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

@martin,

Thanks, works a treat.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0