TextOut 與DrawTextOut

來源:互聯網
上載者:User

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 );

Parameters

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.

Return Value

Nonzero if the function is successful; otherwise 0.

Remarks

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);

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.