我在 WinCE 设备上工作,在 GDI 上工作,因为我正在尝试更改字体类型,我已启用目录项中的所有字体类型(Arial、Comic Sans MS、Courier New、Georgia、Tahoma、Times New Roman、Trebuchet MS,Veradana),我想使用该字体,但这些字体不起作用,设备仅使用默认字体,
我正在使用的代码如下...
void CreateText ()
{
// First, clear all fields.
memset (&logfont, 0, sizeof (logfont));
// Create a GDI Times New Roman font.
logfont.lfHeight = 20;
logfont.lfWidth = 0;
logfont.lfEscapement = 0;
logfont.lfOrientation = 0;
logfont.lfWeight = FW_BOLD;
logfont.lfItalic = TRUE;//FALSE;
logfont.lfUnderline = FALSE;
logfont.lfStrikeOut = FALSE;
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logfont.lfQuality = DEFAULT_QUALITY;
logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
_tcsncpy (logfont.lfFaceName, TEXT("Arial"), LF_FACESIZE); //Comic Sans MS
logfont.lfFaceName[LF_FACESIZE-1] = TEXT('\0'); // Ensure null termination
hfontTimes = CreateFontIndirect (&logfont);
//CreatePointFontIndirect(&logfont);
if (!hfontTimes) {
// CreateFontIndirect failed. Insert code here for error
// handling.
printf("\n CreateFontIndirect failed... ");
}
//SendMessage(NULL,WM_SETREDRAW,(WPARAM)TRUE,NULL);
}
void initiateText ()
{
// Get a GDI DC onto the backbuffer, where you will render the text.
hdcSurface = GetDC (NULL);
// Select the font into the DC.
hfontSave = (HFONT) SelectObject (hdcSurface, hfontTimes);
// Set the background mode to transparent, so there is no
// rectangle behind the text.
SetBkMode (hdcSurface, TRANSPARENT);
}
void printText (HDC hdcSurface,
int screen_x,
int screen_y,
LPTSTR lpszText,
COLORREF color)
{
int bReturn;
// Set text color.
SetTextColor (hdcSurface, color);
bReturn = ExtTextOut (hdcSurface,
screen_x,
screen_y,
0, // No flags set
NULL, // No clipping rectangle
lpszText, // String to display
lstrlen (lpszText), // Number of characters
NULL); // Use default spacing.
}
如上所述,所选字体未显示在屏幕上,请寻求您的建议。