改成Unicode
nWords如果是奇数,就会有乱码

解决方案 »

  1.   

    谢谢xingxingxing, 不过
    请问如何改为Unicode? 我的文本里用了TEXT("..."),它不是改为了宽字符吗??
      

  2.   

    for(i=0;i<nLines;i++)
      TextOut(hdc,0,i*cyChar,szBuffer + i * nWords, nWords);
      
              //这里可能会将汉字切断,因为一个汉字是两个字节
      TextOut(hdc,0,i*cyChar,szBuffer + i * nWords, nLen - i*nWords);
      

  3.   

    另外,我也试过把
    nWords=xWnd/cxChar;
    改为:
    nWords=(xWnd%cxChar ? xWnd/cxChar : xWnd/cxChar - 1);
    以确保nWord为偶数,也不行哦,还是出现乱码...
    怪...
      

  4.   

    to vcmute(横秋):
    如何解决呢??
      

  5.   

      nStart = 0;
      //显示文本
      for(i=0;i<nLines;i++)
      {
      nCurLen =0;
      while(nCurLen<nWords)nCurLen+=szBuffer[nStart+nCurLen]&0x80?2:1;
      TextOut(hdc,0,i*cyChar,szBuffer + nStart, nCurLen);
      nStart += nCurLen;
      }   
              //剩下不够一行的字符最后输出
      TextOut(hdc,0,i*cyChar,szBuffer + nStart, nLen - nStart);>请问如何改为Unicode? 我的文本里用了TEXT("..."),它不是改为了宽字符吗??TEXT并不会自己转宽字符,要根据是否定义_UNICODE宏来决定使用哪种字符
      

  6.   

    VS2003 可能默认定义了 _UNICODE宏
      

  7.   

    用GetTextExtentExPoint好用点
    i =0;
    nStart = 0;
    //显示文本
    while(nStart<nLen)
    {
      SIZE sz;
      GetTextExtentExPoint(hdc,szBuffer+nStart,nLen-nStart,xWnd,&nCurLen,NULL,&sz);
      TextOut(hdc,0,cyChar*i++,szBuffer + nStart, nCurLen);
      nStart += nCurLen;
    }
      

  8.   


    vcmute(横秋)的这行
    while(nCurLen<nWords)nCurLen+=szBuffer[nStart+nCurLen]&0x80?2:1;
    的szBuffer[nStart+nCurLen]&0x80?2:1 这句好像很妙,不过我还没看懂,不过,我在开头定义unicode:
    #define UNICODE
    #include <windows.h>
    就可以的哦
      

  9.   

    Project -> Settings -> C/C++ -> Preprocessor Definitions
    Add UNICODE Definition.
      

  10.   

    摆托,不管你是男是女,不要以小女子开头,有问题直接问就是了,非要加个这玩意,
    到时候满CSDN都是小女子请教美女学编程的问题小妹请教各位大哥女程序员的问题...............................
      

  11.   

    我在VS2003中运行代码,窗口弹出片刻后又错误提示“Run-Time Check Failure #3 - The variable 'xWnd' is being used without being defined.“,就是
    nWords=xWnd/cxChar;     //一行能显示的字数是怎么回事?