Home > Software engineering >  About CFont use different font style problem in VC
About CFont use different font style problem in VC

Time:09-25

In CFont: : CreateFont last parameter in the function: lpszFacename is the name of the font style, after tests found as Microsoft black, Chinese travel model, the end can't draw the corresponding style, such as font
Later, by detecting the registry to check the problems found in the registry no corresponding font library, then I reinstall the corresponding font library, the registry has, through the following code review:
 
LONG ires.
Hkeys hMyKey;
DWORD Type=REG_SZ;
DWORD count=256;
Byte MSTR [256]="";
Ires=RegOpenKeyEx (HKEY_LOCAL_MACHINE,
"SOFTWARE \ \ Microsoft \ \ Windows NT \ \ CurrentVersion \ \ Fonts",
0, KEY_READ, & amp; HMyKey);
If (ERROR_SUCCESS!=ires)
MessageBox (" registry read error ");
The else
Ires=RegQueryValueEx (hMyKey, "Microsoft jas black Bold (TrueType)", 0, & amp; The Type, MSTR, & amp; The count);

If (MSTR [0]=='\ 0')//not installed
{return false; }
The else
{return true; }

Detect the Microsoft black fonts are installed, but draw in addition to the Microsoft black font can display correctly, other font is correct,
What reason is this?
CFont supports all font style or just part of the font, can detailed instructions?

CodePudding user response:

DC can support font EnumFonts or EnumFontFamiliesEx enumeration

 
Oid CSDIt1View: : ontouch * pDC (CDC)
{
CSDIt1Doc * pDoc=GetDocument ();
ASSERT_VALID (pDoc);
if (! PDoc)
return;

//TODO: add the draw code for native data here
Int nSaveDC=pDC - & gt; SaveDC ();

LOGFONT lgFont={0};
LgFont. LfHeight=- MulDiv (72, pDC - & gt; GetDeviceCaps (LOGPIXELSY), 72);
LgFont. LfCharSet=DEFAULT_CHARSET;
_tcscpy_s (lgFont lfFaceName, _T (" Microsoft jas black "));
LgFont. LfWeight=FW_BOLD;

CFont mFont;
MFont. CreateFontIndirect (& amp; LgFont);
CFont * pOldFont=pDC - & gt; SelectObject (& amp; MFont);

PDC - & gt; SetTextColor (RGB (255, 0, 0));
PDC - & gt; TextOut (10, 10, lgFont lfFaceName);

PDC - & gt; SelectObject (pOldFont);
PDC - & gt; RestoreDC (nSaveDC);

}

CodePudding user response:

http://blog.csdn.net/visualeleven/article/details/6248115
  • Related