已知当前字体后,如果计算一个汉字的高和宽(以像素为单位)?还有每个字的间距?也就是说我想计算一个字符串的长度,一像素为单位,该然后计算?谢谢

解决方案 »

  1.   

    BOOL GetTextExtentPoint32(
      HDC hdc,           // handle to DC
      LPCTSTR lpString,  // text string
      int cbString,      // characters in string
      LPSIZE lpSize      // string size
    );这个函数可以得到精确的长、宽。
      

  2.   

    推荐用DrawText函数,最后一个参数用DT_CALCRECT
      

  3.   

    BOOL GetTextExtentPoint32(
      HDC hdc,           // handle to DC
      LPCTSTR lpString,  // text string
      int cbString,      // characters in string
      LPSIZE lpSize      // string size
    );