SetFont problem

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

SetFont problem

16 Aug 2017, 15:07

SetFont command has a difficult problem.

If you need to set the font of the control frequently.
Then there are two options:
1, use GUI.SetFont, but this will lose the default font
2, use Control.SetFont, but will cause the display to be abnormal. For example:

Code: Select all

Gui:=GuiCreate()
t:=Gui.addtext("x1 y0","aasdfsadgsdf")
s:=Gui.addtext("x1 y222","aasdfsadgsdf")
Gui.show("w444 h444")
Sleep(500)
t.SetFont("s24")
s.SetFont("s34")
MsgBox
ImageImage
So, can we add a more concise and direct way?
For example:

Code: Select all

hfont:={size:22,italic:1}
Gui.addtext("f" hfont " x1 y0","aasdfsadgsdf")

CreateFont(obj){
	static	gs:=getdevicecaps(getdc(0), 90 ),this:={"width":[4, "uint"],"escapement":[8, "uint"],"orientation":[12, "uint"],"italic":[20, "uchar"],"underline":[21, "uchar"]
		,"strike":[22, "uchar"],"outprecision":[24, "uchar"],"clipprecision":[25, "uchar"],"pitchandfamily":[27, "uchar"],"charset":[23, "uchar"],"quality":[26, "uchar"]}
	varsetcapacity(logfont, 92, 0)
		rtlmovememory(&logfont, &pum_logfont, 92)
	if objhaskey( obj, "size" )
		numput( -muldiv( abs(obj.delete("size")), gs, 72 ),logfont, 0, "int" )
	if objhaskey( obj, "name" )
		strput(obj.delete("name"), &logfont + 28, 32, "utf-16")
	if objhaskey( obj, "bold" )
		NumPut(obj.delete("bold")?700:400, &LOGFONT,16, uint)

	for i,n in obj
		s:=this[i],NumPut(n, &LOGFONT, s.1, s.2)
	return CreateFontIndirect( &logfont )
}
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: SetFont problem

26 Nov 2017, 01:51

The display is not abnormal. The text is merely truncated because the control is not resized when you change the font. This is unlikely to change.

If you want to use a font handle, you can simply send the WM_SETFONT message.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: gongnl, joedf, mikeyww, prototype_zero, redrum and 24 guests