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;
    }
  • 相关阅读:
    void及void指针含义的深刻解析
    jbpm入门样例
    给字符数组赋值的方法
    linux tar.gz zip 解压缩 压缩命令
    android 文件上传
    职员有薪水了
    sublime配置全攻略
    [置顶] WPF数据修改demo
    Java实现快速排序
    Java实现快速排序
  • 原文地址:https://www.cnblogs.com/aoyihuashao/p/1720942.html
Copyright © 2011-2022 走看看