The Fonts are always ugly... How do you change them? In Win32 that is...
Printable View
The Fonts are always ugly... How do you change them? In Win32 that is...
may I offer parksies famous funcion
:DCode:void SetFont(HWND hWnd, int iPointSize, const char *pcFontName) {
HFONT hTheFont;
HDC hDC = GetDC(hWnd);
int nHeight = -MulDiv(iPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
hTheFont = CreateFont(nHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, pcFontName);
ReleaseDC(hWnd, hDC);
SendMessage(hWnd, WM_SETFONT, (WPARAM)hTheFont, TRUE);
}
No, you may not :p
Kidding, use it all you want! It's free!
(like Simon's mum on thursday nights ;))
If you don't want to set the font of controls, you'll need a device context too. Just replace the line with SendMessage by:
Then return the old font (you will have to select it back into the dc once your done drawing text). Unlike parksies function, you must call this every time you got a new dc. (BeginPaint, GetDC etc.)Code:HFONT hOldFont = SelectObject(hdc, hfont);
One VERY important rule to remember is not to destroy the font after sending WM_SETFONT message. Windows will not make a copy of the font and starangethings can happen if an HFONT is destroyed while it is being refferenced.
Someone's been browsing posts... (look at the date)