代码如下:           LOGFONT  m_lf;  
           memset(&m_lf,  0,  sizeof(LOGFONT));              
           m_lf.lfHeight  = 16;  
           m_lf.lfWidth = 16;            
           strcpy(m_lf.lfFaceName,  "Arial");                
           const char* m_Str = "我";
  
           CDC  dc;  
           dc.CreateDC("DISPLAY",  NULL,  NULL,  NULL);  
           dc.SelectStockObject(SYSTEM_FIXED_FONT);
   
   
           CFont  font;  
           int  i=0,j;  
           CFile  file;  
           file.Open("abc.txt",CFile::modeWrite  |CFile::modeCreate);  
           font.CreateFontIndirect(&m_lf);  
           CFont  *pFont=dc.SelectObject(&font);  
           int mpMode = dc.GetMapMode();
           dc.TextOut(0,0,m_Str); 
   
           CSize cs = dc.GetTextExtent(m_Str);
 
           for(i=0;i<abs(m_lf.lfHeight);i++)  
           {  
                       for(j=0;j<abs(cs.cx);j++)  
                       {  
                                   if(dc.GetPixel(CPoint(j,i))!=RGB(0,0,0))  
                                   {  
                                               file.Write("0",1);  
                                   }else  
                                   {  
                                               file.Write("1",1);  
                                   }  
                       }  
                       file.Write("\r\n",2);  
           }  
           file.Close();  
           dc.SelectObject(pFont);  
           DeleteDC(dc);  
为什么显示出来是16×32点阵的呢?
如何显示我要求的16×16点阵的,谢谢!
还有一个问题:
我想吧CFontDialog里面的size去掉,但是下面的代码为什么不行啊CFontDialog fontDlg(NULL, CF_EFFECTS|CF_SCREENFONTS|CF_NOSIZESEL, NULL, this);

解决方案 »

  1.   

    其实你看一下LOGFONT的MSDN帮助即可知道:
    lfWidth 
    Specifies the average width, in logical units, of characters in the font. If lfWidth is zero, the aspect ratio of the device is matched against the digitization aspect ratio of the available fonts to find the closest match, determined by the absolute value of the difference. 
    是指平均宽度,对不同字符宽度不一样。
    我试了一下,如果'a'为18,‘A’为19。
    汉字比较标准,都为32,主要是把它当作两字节造成的.
    如果你要显示汉字的话,把 m_lf.lfWidth = 16;改为8即可。
      

  2.   

    如果把Charset设为GB2312_CHARSET,则宽度是比较精确的,汉字仍然是双字节。代码如下:
    LOGFONT  m_lf;  
               memset(&m_lf,  0,  sizeof(LOGFONT));              
               m_lf.lfHeight  = 16;  
       if(m_Str[0] & 0x80) //汉字
       {
    m_lf.lfWidth = 8;
       }
       else
       {
       m_lf.lfWidth = 16;
       }           
       m_lf.lfCharSet = GB2312_CHARSET;           strcpy(m_lf.lfFaceName,  "Arial");     
      
      

  3.   

    用SYSTEM_FIXED_FONT字体就可以了,不用创建字体,至于宽度和高度什么的都不用设置
      

  4.   

    字体有几种,对于要精确定位最好用等宽字体,至于哪些是等宽字体可以从网上查到
    你可以用CDC::GetTextExtent获取用当前字体输出一字符串所需占用的宽度和高度
    经过计算后再用CDC::DrawText绘制
      

  5.   

    CFont 创建时用 GB2312_CHARSET,字体用_T("宋体"),宽度16,高度0
      

  6.   

    用SYSTEM_FIXED_FONT字体就可以了,不用创建字体,至于宽度和高度什么的都不用设置
    都是16,这是最简单的方法
      

  7.   

    WideCharToMultiByte ( CP_ACP,                // ANSI 代码页
      WC_COMPOSITECHECK, // 检查重音字符
      wc,         // 原Unicode 串
      -1,                    // -1 意思是串以0x00结尾
                                  s,          // 目的char字符串
                                  sizeof(s),  // 缓冲大小
                                  NULL,                  // 肥缺省字符串
                                  NULL );                // 
    //int mapMode = GetMapMode(dcMem);
    //display the word converted from unicode code.  MM_TEXT
    TextOut(dcMem,column,currentDisplayRow,s,strlen(s));
    if(s[0] & 0x80) 
    {
    GetTextExtentPoint32(dcMem,s,2,cs);
    }
    else
    {
    GetTextExtentPoint32(dcMem,s,1,cs);
    }
    StretchBlt(dc,column,currentDisplayRow,width,height,dcMem,column,currentDisplayRow,cs->cx,cs->cy,SRCCOPY);
    column += width;