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;
    }
  • 相关阅读:
    Python异常处理
    奇异值分解(SVD)详解及其应用
    上楼梯问题
    Python面向对象(特殊成员)
    Best Time to Buy and Sell Stock II
    String to Integer (atoi)
    Gas Station
    N-Queens II
    Letter Combinations of a Phone Number
    N-Queens
  • 原文地址:https://www.cnblogs.com/aoyihuashao/p/1720942.html
Copyright © 2011-2022 走看看