TextOut可以输出文本,DrawText死活不行

几罗星人 2014-08-26 04:23:46

#include <string>
using namespace std;

case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);

wstring str = L"abcdefg";
//TextOut(hdc,0,0,str.data(),str.size()); // 可以输出
RECT Rect;
Rect.left = 0;
Rect.top = 0;
Rect.right = 1335;
Rect.bottom = 868;
//SetMapMode(hdc,MM_HIENGLISH); // 有没有都是不行!
// 死活不行!
DrawText(hdc,str.data(),str.size(),&Rect,DT_CALCRECT|TA_LEFT|TA_TOP|TA_NOUPDATECP);
// 直接写出文本也不行
DrawText(hdc,L"abcdefg",7,&Rect,DT_CALCRECT|TA_LEFT|TA_TOP|TA_NOUPDATECP);
EndPaint(hWnd, &ps);
break;
}

就是不知道为什么不行,囧!求解释一下为什么不行,或这给一个能用的代码。注意不是MFC,是Win32。上面的代码是用Win32项目向导建立的窗口应用程序,仅仅是在向导给的消息循环里给 WM_PAINT消息写了输出文本的代码。
...全文
158 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
几罗星人 2014-08-27
  • 打赏
  • 举报
回复
引用 4 楼 movsd 的回复:
DT_CALCRECT Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.
我喷血了,英文不好考翻译工具的孩纸硬伤啊
movsd 2014-08-26
  • 打赏
  • 举报
回复
DT_CALCRECT Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.
movsd 2014-08-26
  • 打赏
  • 举报
回复
DT_CALCRECT: 计算文本大小,并返回到RECT,不输出文本
Saleayas 2014-08-26
  • 打赏
  • 举报
回复
SetTextAlign
zilaishuichina 2014-08-26
  • 打赏
  • 举报
回复
SetTextColor(HDC,RGB(0,0,0)); ?

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧