Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29278 Discussions

Changing the font for one control in a dialog box

davidgraham
Beginner
656 Views

I want to make the text in one label on a dialog box bigger than the rest. I can change the font for the whole dialog box, how do I do it for one control?

It's a windows API application.

Thanks agian.

David

0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
656 Views
[bash]hControl = GetDlgItem(hDlg, IDC_CONTROL)
ret = SendMessage(hControl, WM_SETFONT, hFont, TRUE)[/bash]
0 Kudos
anthonyrichards
New Contributor III
656 Views

Or

ret = SendDlgItemMessage(hDlg, IDC_CONTROL, WM_SETFONT, hFont, TRUE)

0 Kudos
davidgraham
Beginner
656 Views

Thanks, what I get is what I want, the text stands out - but I think it's by luck.

I can't cange the height or the font even though I change H1 and 'Arial'.

I also don't know if the other commands are necessary, do I need the Select Object(s) & Delete Objects?

H1=0
hfont=CreateFont(H1,0,0,0,FW_NORMAL,0,0,0, &
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, &
DEFAULT_QUALITY,DEFAULT_PITCH,'Arial'c)
hFontOld=SelectObject(hDC,hfont)
iret=SendDlgItemMessage(hWnd,IDC_ACTION,WM_SETFONT,hFont,TRUE)
iret=SelectObject(hDC,hFontOld)

iret=DeleteObject(hFont)

David

0 Kudos
Jugoslav_Dujic
Valued Contributor II
656 Views

I'm not sure about the height issue. In my opinion, it should work with any height, but I don't have time to test it.

You should not SelectObject -- there is no DC to select into. The control will select the font into its own DC when it redraws itself, but it should not concern you.

You must not DeleteObject as long as the control "owns" the font. Doing so will lead to unpredictable effects... such as one you experienced with wrong height? You should DeleteObject on WM_DESTROY (or after you substitute another font using WM_SETFONT); in any case, the GDI memory leak will be negligible even if you forget.

0 Kudos
Reply