TextOut 与DrawTextOut

Writes a character string at the specified location using the currently selected font.

 
virtual BOOL TextOut(
   int x,
   int y,
   LPCTSTR lpszString,
   int nCount 
);
BOOL TextOut(
   int x,
      int y,
      const CString& str 
);

Collapse imageParameters

x

Specifies the logical x-coordinate of the starting point of the text.

y

Specifies the logical y-coordinate of the starting point of the text.

lpszString

Points to the character string to be drawn.

nCount

Specifies the number of bytes in the string.

str

A CString object that contains the characters to be drawn.

Collapse imageReturn Value

Nonzero if the function is successful; otherwise 0.

Collapse imageRemarks

Character origins are at the upper-left corner of the character cell. By default, the current position is not used or updated by the function.

If an application needs to update the current position when it calls TextOut, the application can call the SetTextAlign member function with nFlags set to TA_UPDATECP. When this flag is set, Windows ignores the x and y parameters on subsequent calls to TextOut, using the current position instead.

 

大概意思是说当调用函数SetTextAlign ,参数为TA_UPDATECP情况下,Windows调用TextOut就会忽视x,y参数值,而用当前位置替代。


void CMy0121DrawTextView::OnDraw(CDC* pDC)
{
 
 CMy0121DrawTextDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 // TODO: add draw code for native data here
 COLORREF crOld = SetTextColor(pDC->GetSafeHdc(),RGB(255,0,0));
 TextOut(pDC->GetSafeHdc(),12,13,_T("Red"),3);
 SetTextAlign(pDC->GetSafeHdc(),TA_UPDATECP);
 SetTextColor(pDC->GetSafeHdc(),RGB(0,255,0));
 TextOut(pDC->GetSafeHdc(),12,30,_T("Green"),5);  //文本不会覆盖
 TextOut(pDC->GetSafeHdc(),12,30,_T("Green Two"),9); //文本不会覆盖
 TextOut(pDC->GetSafeHdc(),12,30,_T("Green Two"),9); //文本不会覆盖

 RECT rcText;
 rcText.left = 50;
 rcText.top = 50;
 rcText.bottom = 100;
 rcText.right = 150;
 SetTextAlign(pDC->GetSafeHdc(),TA_NOUPDATECP);   // 这个必须有,要不显示不正常
 DrawText(pDC->GetSafeHdc(),"DrawRect",8,&rcText,DT_LEFT | DT_SINGLELINE |DT_END_ELLIPSIS);
 SetTextColor(pDC->GetSafeHdc(),crOld);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值