VS2005 DRAWTEXT的使用

    技术2022-05-19  22

    DrawText的描述

     

    int DrawText( HDC hDC, // handle to DC LPCTSTR lpString, // text to draw int nCount, // text length LPRECT lpRect, // formatting dimensions UINT uFormat // text-drawing options );

     

     

     

    void CTESTView::OnDraw(CDC* pDC){ CTESTDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc);

     // TODO: 在此处为本机数据添加绘制代码

     

     

     //Drawtext 第一个参数hdc HDC hDC;   hDC   =   pDC->m_hDC;  //将pDC的变量赋给hDC

     

     //Drawtext 第二个参数RECT

     RECT rcText;

     rcText.left = 10; rcText.top = 30; rcText.right = 100; rcText.bottom = 50;

    //或GetClientRect(&rcText);

     

     //Drawtext 第三个参数RECT

     

    const wchar_t *str=_T("Test");      //宽字符的string,否则报错

    size_t strlength;                             //字符长度

    strlength=wcsnlen(str,strlength);  //得到字符串长度

     

    //设置字符颜色

    pDC->SetTextColor(RGB(255, 0, 0));  //红色

     

    //最后一步

    DrawText(hDC,str,strlength,&rcText,DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);}


    最新回复(0)