Hi all, I am practicing with win api function CreateFont. This is my code.
After setting my new font, button's text is dissappearing. How to fix it. This
is my CreateFont wrapper function.
proc createFontHadle(wHandle : HWND, fontName : string, fSize : int32,
fWeight : int32 = 400,
bItalics : bool = false, bUnderLine : bool = false) :
HFONT =
var hFo : HFONT = 0
var dcHandle : HDC
var iHeight : int32
var LOGICPIXELSY : int32 # this is not declared in win api library.
var seventyTwo : int32 = 72 # compiler get angry when i use 72 inside
the function
dcHandle = GetDC(wHandle) # here, wHandle is window's handle. Not
button's handle
iHeight = MulDiv(fSize, GetDeviceCaps(dcHandle, LOGICPIXELSY),
seventyTwo)
discard ReleaseDC(wHandle, dcHandle)
hFo = CreateFont(iHeight, 0,0,0, fWeight, bItalics, bUnderLine, false,
1,
OUT_DEAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH, fontName)
return hFo
Run
And this the wrapper for send message
proc setFont*(wHandle : HWND, chHwnd : HWND, fontName : string = "Tahoma",
fontSize : int32 = 10) =
var fHandle : HFONT = createFontHadle(wHandle, fontName, fontSize)
discard SendMessage(chHwnd, WM_SETFONT, WPARAM(fHandle), 1)
Run