As Titile, 应该有这方面的API函数吧。
另外一个相关的问题是,比如我选择宋体,高度为16的字体,输出的字都是撑满16个象素高度的,是否有函数可以让其字体输出略微低于其所定的高度?比如上下都略微缩低一点?请教有关字体和字体输出方面的高手,在此先谢了。

解决方案 »

  1.   

    CDC::GetTextExtent 
    Call this member function to compute the width and height of a line of text using the current font to determine the dimensions.
      

  2.   

    GetTextExtentPoint32
    The GetTextExtentPoint32 function computes the width and height of the specified string of text. BOOL GetTextExtentPoint32(
      HDC hdc,           // handle to DC
      LPCTSTR lpString,  // text string
      int cbString,      // characters in string
      LPSIZE lpSize      // string size
    );
      

  3.   

    得到size后,ExtTextOut中设置lprcExtTextOut
    The ExtTextOut function draws text using the currently selected font, background color, and text color. You can optionally provide dimensions to be used for clipping, opaquing, or both. BOOL ExtTextOut(
      HDC hdc,          // handle to DC
      int X,            // x-coordinate of reference point
      int Y,            // y-coordinate of reference point
      UINT fuOptions,   // text-output options
      CONST RECT* lprc, // optional dimensions
      LPCTSTR lpString, // string
      UINT cbCount,     // number of characters in string
      CONST INT* lpDx   // array of spacing values
    );
      

  4.   

    或设置DrawText参数的lpRectDrawText
    The DrawText function draws formatted text in the specified rectangle. It formats the text according to the specified method (expanding tabs, justifying characters, breaking lines, and so forth). To specify additional formatting options, use the DrawTextEx function. int DrawText(
      HDC hDC,          // handle to DC
      LPCTSTR lpString, // text to draw
      int nCount,       // text length
      LPRECT lpRect,    // formatting dimensions
      UINT uFormat      // text-drawing options
    );
      

  5.   

    多谢各位, 我目前使用GetTextExtentPoint32函数获得制定字符串的长度,但是当我的LOGFONT使用lfItalic = 1(斜体)的时候,获得的长度好像是有误差的。这是为什么呢