winApi一日一练之 SetTextColor (和Textout)函数

记得先要#include <iostream>
////声明字符串
std::wstring strShow(_T("Test String"));

hdc = BeginPaint(hWnd, &ps);
TextOut(hdc,10,30,strShow.c_str(),(int)strShow.length());

SetTextColor(hdc,RGB(0,255,0));
TextOut(hdc,10,60,strShow.c_str(),(int)strShow.length());

SetTextColor(hdc,RGB(12,56,89));
TextOut(hdc,10,80,strShow.c_str(),(int)strShow.length());

// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);



drawText 调用示例:

////声明字符串
std::wstring strShow(_T("Test String"));

////声明一个矩形
RECT rcText;
rcText.left = 10;
rcText.right=100;
rcText.top = 20;

hdc = BeginPaint(hWnd, &ps);

DrawText(hdc,strShow.c_str(),(int)strShow.length(),&rcText,
DT_LEFT|DT_SINGLELINE|DT_END_ELLIPSIS);

SetTextColor(hdc,RGB(0,255,0));
rcText.left = 10;
rcText.top = 40;


DrawText(hdc,strShow.c_str(),(int)strShow.length(),&rcText,
DT_LEFT|DT_SINGLELINE|DT_END_ELLIPSIS);
rcText.left = 10;
rcText.top = 60;

SetTextColor(hdc,RGB(12,56,89));
DrawText(hdc,strShow.c_str(),(int)strShow.length(),&rcText,
DT_LEFT|DT_SINGLELINE|DT_END_ELLIPSIS);

// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);


你可能感兴趣的:(winApi一日一练之 SetTextColor (和Textout)函数)