请教一个Mfc窗口显示的问题

IT保安 2014-09-17 08:51:39
void CTextView::OnDraw(CDC* pDC) //响应wm_paint消息
{
CTextDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
m_str = CString("我是写在OnDraw函数之中");
HDC hdc;
PAINTSTRUCT ps;
hdc = ::BeginPaint(m_hWnd,&ps);
::TextOut(hdc,0,45,m_str,strlen(m_str));
::EndPaint(m_hWnd,&ps);
// pDC->TextOut(0,0,m_str);


用全局函数就不显示字符串啊,只有当我用pDC指针调用textout才能显示出字符串,请问为什么呢?

...全文
150 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-09-19
  • 打赏
  • 举报
回复
m_str如果是Unicode编码的CString,能对其用strlen才怪!
席戛戛 2014-09-19
  • 打赏
  • 举报
回复
strlen(m_str)) 返回值是什么?
孤影品茗 2014-09-18
  • 打赏
  • 举报
回复
你有没有看看,用全局TextOut的时候,屏幕左上角的位置有没有 strlen是系统函数,可以对CString使用,编译器会自动做转换,没问题的
赵4老师 2014-09-18
  • 打赏
  • 举报
回复
m_str是什么类型?能对其strlen吗? CString::GetLength int GetLength( ) const; Return Value A count of the bytes in the string. Remarks Call this member function to get a count of the bytes in this CString object. The count does not include a null terminator. For multibyte character sets (MBCS), GetLength counts each 8-bit character; that is, a lead and trail byte in one multibyte character are counted as two bytes. Example The following example demonstrates the use of CString::GetLength. // example for CString::GetLength CString s( "abcdef" ); ASSERT( s.GetLength() == 6 ); CString Overview | Class Members | Hierarchy Chart See Also CString::IsEmpty

64,683

社区成员

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

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