How can I create labels with the same appearance as in the standard applications?
By Yaroslav Goncharov, May 13, 2002.
Question
I have noted that labels in the standard Smartphone 2002 applications (for example, Inbox)
use font that differs from the dialog font. How to create the same labels in my application?
Answer
The standard Smartphone 2002 applications use 11-point bold Nina. This is a standard Smartphone
2002 system font. The following code snippet shows how to create this font. This code uses
a hardcoded font height. Request the font height from the system to consider a large font.
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
HDC hdc = ::GetDC(NULL);
lf.lfHeight = -11 * GetDeviceCaps(hdc, LOGPIXELSY) / 72;
::ReleaseDC(NULL, hdc);
lf.lfWeight = FW_SEMIBOLD;
HFONT hFont = CreateFontIndirect(&lf);
Now you can assign this font to static controls in your dialog box. A good place to do it is
a WM_INITDIALOG handler.
::SendDlgItemMessage(hDlg, IDC_STATIC_TEST, WM_SETFONT, (int) hFont, 0);
Do not forget to call the DeleteObject function to delete the font when it is no longer needed; for example, after the dialog destroys the control.
Discuss
Discuss this QA.
Here you can write your comments and read comments of other developers.
|