如果nCount = -1,则pdc->GetOutputTextExtent()崩溃。为什么?手册上写道:
nCount指定字符串中的字符数。如果nCount为-1,则计算长度。
发布于 2019-04-26 23:46:54
看起来手册是错的。在内部,它是这样实现的:
_AFXWIN_INLINE CSize CDC::
GetOutputTextExtent(LPCTSTR lpszString, int nCount) const
{
ASSERT(m_hDC != NULL);
SIZE size;
VERIFY(::GetTextExtentPoint32(m_hDC, lpszString, nCount, &size));
return size;
}而且,GetTextExtentPoint32文档没有提到-1将自动计算。
但是,有一个重载同级只接受一个字符串,该字符串本身会进行计数:
_AFXWIN_INLINE CSize CDC::GetOutputTextExtent(const CString& str) const
{
ASSERT(m_hDC != NULL);
SIZE size;
VERIFY(::GetTextExtentPoint32(m_hDC, str, (int)str.GetLength(), &size));
return size;
}https://stackoverflow.com/questions/55871010
复制相似问题