Click to See Complete Forum and Search --> : Fonts
SteveCRM
Apr 26th, 2001, 11:46 AM
How would I add different fonts to my buttons and statics? :confused:
parksie
Apr 26th, 2001, 12:22 PM
You need to send it a WM_SETFONT message with the handle to a newly created HFONT:
SendMessage(hWnd_Edit, WM_SETFONT, hTheFont, TRUE); // TRUE = redraw after setting
To create the font, use the CreateFont function:
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);
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:
SteveCRM
Apr 26th, 2001, 12:41 PM
should I put this right under WinMain?
so It would look like this?
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
parksie
Apr 26th, 2001, 12:46 PM
You could do, or you could separate it out into a separate function that you call from WinMain:
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");
// ...
}
SteveCRM
Apr 26th, 2001, 01:03 PM
Nothing Changes...not even sizes :confused:
parksie
Apr 26th, 2001, 01:23 PM
Hmmm...it worked for me when I just tested that function :confused:
(I used the (WPARAM) cast as decided in our MSN conversation...)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.