zoukankan      html  css  js  c++  java
  • VC DrawText显示多行,包括设置行距。

    int   DrawMultLineText(HDC   hDC   ,   int   nXStart   ,   int   nYStart   ,   int   nWidth   ,   int   nRowHeight   ,   LPCTSTR   pBuff)   
    {
    TEXTMETRIC tm;

    LPCTSTR pChar;

    if(!GetTextMetrics(hDC , &tm))
    return 0;
    CPoint posStart , posCurr;
    int nRowCount = 0;
    pChar
    = pBuff;

    posStart.SetPoint(nXStart , nYStart);

    for(; *pChar ; pChar++)
    {
    if(*pChar == '\t')
    {
    MovePos(posStart , posCurr , nWidth ,nRowHeight , tm.tmAveCharWidth ,
    4);
    }
    else
    {
    if(*pChar == '\r')
    {
    posCurr.y
    += nRowHeight;
    posCurr.x
    = posStart.x;
    if( *(pChar + 1) == '\n')
    pChar
    ++;
    }
    else
    if(*pChar == '\n')
    {
    posCurr.y
    += nRowHeight;
    posCurr.x
    = posStart.x;
    }
    else
    if( IsChineseChar(pChar))
    {
    TextOut(hDC , posCurr.x , posCurr.y ,pChar ,
    2);
    MovePos(posStart , posCurr , nWidth ,nRowHeight , tm.tmMaxCharWidth ,
    1) ;
    pChar
    ++;
    }
    else
    {
    TextOut(hDC , posCurr.x , posCurr.y ,pChar ,
    1);
    MovePos(posStart , posCurr , nWidth ,nRowHeight , tm.tmAveCharWidth ,
    1);
    }
    }
    }
    return (posCurr.y + posStart.y) / nRowHeight;
    }

    void MovePos(const POINT &posStart , POINT &posCurr , int nColWidth , int nRowHeight , int nCharWidth , int nCount)
    {
    int i;
    if(nColWidth < nCharWidth)
    return;
    if(posStart.x > posCurr.x)
    posCurr.x
    = posStart.x;
    if(posStart.y > posCurr.y)
    posCurr.y
    = posStart.y;

    for(i = 0 ; i < nCount ; i++)
    {
    posCurr.x
    += nCharWidth;
    if(posCurr.x > nColWidth)
    {
    posCurr.x
    = posStart.x;
    posCurr.y
    += nRowHeight;
    }
    }
    }
    BOOL IsChineseChar(LPCTSTR str)
    {
    return *str < 0 && (*(str + 1)) < 0;
    }
  • 相关阅读:
    72. Edit Distance
    电脑常识
    java try·····catch·····异常处理学习
    java链接sqlserver数据库
    HTTP Status 500
    初识NDA
    Sublime Text_v2.02包含中文包以及使用方法
    ol 与ul 的区别
    word-break: break-all word-break:keep-all word-wrap: break-word三者的区别
    用deamon打开ISO文件,提示命令行错误!!
  • 原文地址:https://www.cnblogs.com/aoyihuashao/p/1720942.html
Copyright © 2011-2022 走看看