您的位置:首页 > 其它

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

2011-10-14 13:52 411 查看
记得先要#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 string