How would I add different fonts to my buttons and statics? :confused:
Printable View
How would I add different fonts to my buttons and statics? :confused:
You need to send it a WM_SETFONT message with the handle to a newly created HFONT:
To create the font, use the CreateFont function:Code:SendMessage(hWnd_Edit, WM_SETFONT, hTheFont, TRUE); // TRUE = redraw after setting
See the PSDK for more info on the parameters...there's lots of them :eek: I would post it here but it's too long :rolleyes:Code:HFONT hTheFont;
HDC hEditDC = GetDC(hWnd_Edit);
int nHeight = -MulDiv(26 /* Point size required */, GetDeviceCaps(hEditDC, 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, "Times New Roman");
ReleaseDC(hEditDC);
should I put this right under WinMain?
so It would look like this?
Code:HFONT hTheFont;
HDC hEditDC = GetDC(ghWnd_PlayFile);
int nHeight = -MulDiv(26 /* Point size required */, GetDeviceCaps(hEditDC, 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, "Wingdings 3");
ReleaseDC(ghWnd_PlayFile, hEditDC);
SendMessage(ghWnd_PlayFile, WM_SETFONT, hTheFont, TRUE); // TRUE = redraw after setting
You could do, or you could separate it out into a separate function that you call from WinMain:
Code: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, hTheFont, TRUE);
}
int WinMain(...) {
// ...
SetFont(ghWnd_Edit, 26, "Wingdings 3");
// ...
}
Nothing Changes...not even sizes :confused:
Hmmm...it worked for me when I just tested that function :confused:
(I used the (WPARAM) cast as decided in our MSN conversation...)