关于网友提出的“ 请教一个Mfc窗口显示的问题”问题疑问,本网通过在网上对“ 请教一个Mfc窗口显示的问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 请教一个Mfc窗口显示的问题
描述: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才能显示出字符串,请问为什么呢?
解决方案1: strlen(m_str)) 返回值是什么?
解决方案2: 你有没有看看,用全局TextOut的时候,屏幕左上角的位置有没有
strlen是系统函数,可以对CString使用,编译器会自动做转换,没问题的
解决方案3: m_str如果是Unicode编码的CString,能对其用strlen才怪!
解决方案4: 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
以上介绍了“ 请教一个Mfc窗口显示的问题”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3637160.html