This is the function you might want to use for font change. I created it for the HiEdit. Only the last line is related to HiEdit, so you can use it for richedit, perhaps even unchanged.
Code:
HE_SetFont(hEdit, pFont="") {
local height, weight, italic, underline, strikeout , nCharSet
local hFont
static WM_SETFONT := 0x30
;parse font
italic := InStr(pFont, "italic") ? 1 : 0
underline := InStr(pFont, "underline") ? 1 : 0
strikeout := InStr(pFont, "strikeout") ? 1 : 0
weight := InStr(pFont, "bold") ? 700 : 400
;height
RegExMatch(pFont, "(?<=[S|s])(\d{1,2})(?=[ ,])", height)
if (height = "")
height := 10
RegRead, LogPixels, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI, LogPixels
height := -DllCall("MulDiv", "int", Height, "int", LogPixels, "int", 72)
;face
RegExMatch(pFont, "(?<=,).+", fontFace)
if (fontFace != "")
fontFace := RegExReplace( fontFace, "(^\s*)|(\s*$)") ;trim
else fontFace := "MS Sans Serif"
;create font
hFont := DllCall("CreateFont", "int", height, "int", 0, "int", 0, "int", 0
,"int", weight, "Uint", italic, "Uint", underline
,"uint", strikeOut, "Uint", nCharSet, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "str", fontFace)
SendMessage,WM_SETFONT,hFont,TRUE,,ahk_id %hEdit%
return ErrorLevel
}
THe usage:
Code:
fStyle := "s12 bold" , fFace := "Courier New"
HE_SetFont( hEdit, fStyle "," fFace)