我是采用int DrawText(HDC hDC, LPCTSTR lpString, int nCount, LPRECT lpRect, UNIT uFormat); 显示文字,为了更好的进行排版,我首先计算了最长的一行的字符数line_max,以及行数,以此来判断lpRect的合适大小
请问:
  1、当我计算出了line_max,我怎么得到lpRect的宽度?是不是
line_max×LogFont.lfWidth?LogFont.lfWidth是不是对于不同的字符会不同,比如w和i
  2、如果要让所有的字符显示的宽度一样,需要怎样设置?

解决方案 »

  1.   

    参考: CSize fontsize;
    CString str="XXXX";
    fontsize = dc.GetTextExtent(str);
      

  2.   

    我试过了,和实际的还是有点差别,MSDN上解释说:Because some devices do not place characters in regular cell arrays—that is, they carry out kerning—the sum of the extents of the characters in a string may not equal the extent of the string
    我想是不是我问的问题“LogFont.lfWidth是不是对于不同的字符会不同,比如w和i”,但还是不知道怎么解决好~~