2010年5月14日星期五

WinAPI Font

CreateFont

  函数功能:该函数创建一种有特殊性的逻辑字体,此逻辑字体可以在后面被任何设备选择。
  函数原型:
  HFONT CreateFont(
  int nHeight, // logical height of font
  int nWidth, // logical average character width
  int nEscapement, // angle of escapement
  int nOrientation, // base-line orientation angle
  int fnWeight, // font weight
  DWORD fdwItalic, // italic attribute flag
  DWORD fdwUnderline, // underline attribute flag
  DWORD fdwStrikeOut, // strikeout attribute flag
  DWORD fdwCharSet, // character set identifier
  DWORD fdwOutputPrecision, // output precision
  DWORD fdwClipPrecision, // clipping precision
  DWORD fdwQuality, // output quality
  DWORD fdwPitchAndFamily, // pitch and family
  LPCTSTR lpszFace // pointer to typeface name string
  );
  参数:
  nHeight:指定字体的字符单元或字符的逻辑单位高度,字符的高度值(也被称为em高度)是指字符单元高度值减去内部标头值。字体映射器以如下方式解释nHeight指定的值,各值含义为:
  >0:字体映射器转换这个值以设备单位,并和已有字体的单元高度相匹配。
  0:字体映射器转换在选择匹配时用一个缺省的高度值。
  <0:字体映射器转换这个值到设备单位,并将它的绝对值和已有字体的字符高度相匹配。 nheight="-MulDiv(PointSize,">
Sample
HFONT MyCreateFont(int nHeight, DWORD dwCharSet, LPCTSTR lpName)
{
return(CreateFont(nHeight, 0, 0, 0,
FW_DONTCARE,
FALSE, FALSE, FALSE,
dwCharSet,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE,
lpName));
}


在调用的时候,如以下例子建立字体
myFont1 = MyCreateFont(20, ANSI_CHARSET, _T("News Gothic"));
myFont2 = MyCreateFont(20, SHIFTJIS_CHARSET, _T("HGS正楷書体"));

在输出前选择对应字体
SelectObject(hdc, myFont1);

myRGB = RGB(255, 0, 0);
SetTextColor(hdc, myRGB);

//To display text in specified type
myRect.top = 100;
myRect.bottom = 300;
myRect.left = 0;
myRect.right = 480;

DrawText(hdc, szTextEN, -1, &myRect, MY_TEXT_FORMAT);

MY_TEXT_FORMAT --> DT_LEFT | DT_WORDBREAK

没有评论: