Windows API one-day training (24) drawtext Function

Source: Internet
Author: User
Tags drawtext textout

The drawtext function and the preceding textout function are both text output functions, but they are different. The drawtext function is a formatting output function, but the textout function does not. Therefore, the drawtext function is more powerful than the textout function. It can align the text output to the left, right, or center, and adapt the text to the output rectangle. If it exceeds the limit, it can be truncated, or, it is displayed as an ellipsis. The drawtext function must be used for table display.

The drawtext function is declared as follows:
Winuserapi
Int
Winapi
Drawtexta (
_ In HDC,
_ Inout_ecount (cchtext) lpcstr lpchtext,
_ In int cchtext,
_ Inout lprect LPRC,
_ In uint format );
Winuserapi
Int
Winapi
Drawtextw (
_ In HDC,
_ Inout_ecount (cchtext) lpcwstr lpchtext,
_ In int cchtext,
_ Inout lprect LPRC,
_ In uint format );
# Ifdef Unicode
# Define drawtext drawtextw
# Else
# Define drawtext drawtexta
# Endif //! Unicode
HDCIs the handle of the current device.
LpchtextIs the first buffer address of the output text.
CchtextIs the number of characters in the output text.
LPRCIs the display area of the output.
FormatWhat format is used for output.

An example of calling this function is as follows:
#001 //
#002 // The output is displayed on the interface.
#003 //
#004 // Cai junsheng 2007/08/27 QQ: 9073204 Shenzhen
#005 //
#006 void ccaiwinmsg: ondraw (HDC)
#007 {
#008 //
#009 STD: wstring strshow (_ T ("Implementation of the C ++ window class, 2007-08-27 "));
#010 textout (HDC, 10, 10, strshow. c_str (), (INT) strshow. Length ());
#011
#012 // set the color of the output string.
#013 colorref crold = settextcolor (HDC, RGB (255, 0, 0 ));
#014
#015 rect rctext;
#016
#017 // The display is incomplete.
#018 rctext. Left = 10;
#019 rctext. Top = 30;
#020 rctext. Right = 100;
#021 rctext. Bottom = 50;
#022
#023 drawtext (HDC, strshow. c_str (), (INT) strshow. Length (), & rctext,
#024 dt_left | dt_singleline | dt_end_ellipsis );
#025
#026 // completely displayed, left aligned.
#027 rctext. Left = 10;
#028 rctext. Top = 50;
#029 rctext. Right = 300;
#030 rctext. Bottom = 80;
#031
#032 drawtext (HDC, strshow. c_str (), (INT) strshow. Length (), & rctext,
#033 dt_left | dt_singleline | dt_end_ellipsis );
#034
#035
#036 settextcolor (HDC, RGB (0, 0, 255 ));
#037 // completely displayed, right aligned.
#038 rctext. Left = 10;
#039 rctext. Top = 80;
#040 rctext. Right = 300;
#041 rctext. Bottom = 110;
#042
#043 strshow = _ T ("A & BCD ");
#044 drawtext (HDC, strshow. c_str (), (INT) strshow. Length (), & rctext,
#045 dt_right | dt_singleline | dt_end_ellipsis );
#046
#047
#048 //
#049 settextcolor (HDC, crold );
#050}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.