2013-05-07 30 views
0

我的工作在WinCE的设备,在我试图改变字体类型的GDI的工作,我已经启用的目录项的所有字体类型(宋体,Comic Sans字体MS,快递New,Georgia,Tahoma,Times New Roman,Trebuchet MS,Veradana),我想使用那些字体,但那些不工作,设备只使用默认字体,如何更改WINCE设备字体类型

我使用的代码如下。

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. 
} 

如上所述,所选字体不显示在屏幕上,寻找您的建议。

+0

'我想使用的字体,而那些没有工作,设备只能工作与默认字体,'你这个意思是什么?你如何测试?如果您想测试是否添加字体,请打开Word Editor并查看“字体”的下拉菜单。就像这样,只有您已经测试过? – GNKeshava 2013-05-07 06:30:36

回答

0

步骤1是确定字体实际上是在系统中并注册。调用EnumFontFamilies将告诉您操作系统实际看到的内容,以及您需要用于lfFaceName参数的确切名称。

编辑

如果字体不显示当您枚举,那么告诉我,他们是不是在OS。可能有多种原因没有进入操作系统。查看操作系统映像的BUILDRELDIR,看看它们是否在那里。如果他们是,那么它听起来像你没有makeimg让他们进入实际的操作系统。同时检查ce.bib以查看构建系统是否实际被告知包含它们(某些项目或平台文件可能已明确排除它们)。

最后,蛮力的办法是,以确保字体文件是在设备上,然后调用AddFontResource您的应用程序启动时。

+0

我用EnumFontFamilies()函数,在默认字体是只给“宋体”,但启用了目录项的所有字体它需要显示其他字体也不过剩下的字体没有给人什么可能是错误的。 – Mujeeb 2013-05-08 06:38:25

+0

thsnks您的回复,我 – Mujeeb 2013-05-09 05:43:59

+0

在操作系统映像和ce.bib文件已检查在两个地方的字体都存在,我都试过AddFontResource()它给错误INVALID_DATA – Mujeeb 2013-05-09 06:26:55