debug Assert Failed
yrb 2006-04-28 05:23:08 我从CWnd派生了一个类,用于提示信息,为什么在调试模式下总是出现assert失败的错误?
头文件(省略无关部分):
/////////////////////////////////////////////////////////////////////////////
// CYFTipWnd window
class CYFTipWnd : public CWnd
{
// Construction
public:
CYFTipWnd();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CYFTipWnd)
protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL
// Implementation
public:
void SetContent(CString Text);
virtual ~CYFTipWnd();
// Generated message map functions
protected:
//{{AFX_MSG(CYFTipWnd)
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CString m_Text;
CFont m_Font;
};
源文件(省略无关部分):
CYFTipWnd::CYFTipWnd()
{
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
lf.lfCharSet = GB2312_CHARSET;
lf.lfHeight = 12;
strcpy(lf.lfFaceName, "宋体");
this->m_Font.CreateFontIndirect(&lf);
}
CYFTipWnd::~CYFTipWnd()
{
}
BEGIN_MESSAGE_MAP(CYFTipWnd, CWnd)
//{{AFX_MSG_MAP(CYFTipWnd)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CYFTipWnd::OnPaint()
{
CPaintDC dc(this);
CBrush BKBrush;
BKBrush.CreateSolidBrush(GetSysColor(COLOR_INFOBK));
CRect rcClient;
this->GetClientRect(&rcClient);
dc.FillRect(&rcClient, &BKBrush);
CFont * pOldFont = dc.SelectObject(&this->m_Font);
int OldBkMode = dc.SetBkMode(TRANSPARENT);
dc.TextOut(2, 2, this->m_Text);
dc.SetBkMode(OldBkMode);
dc.SelectObject(pOldFont);
}
BOOL CYFTipWnd::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(NULL);
return CWnd::PreCreateWindow(cs);
}
void CYFTipWnd::SetContent(CString Text)
{
this->m_Text = Text;
CPaintDC dc(this);
CFont * SaveFont = dc.SelectObject(&this->m_Font);
CSize size = dc.GetTextExtent(Text);
dc.SelectObject(SaveFont);
CRect r;
this->GetWindowRect(&r);
if(r.Width() < size.cx || r.Height() < size.cy)
{
r.bottom = r.top + size.cy;
r.right = r.left + size.cx;
this->MoveWindow(&r);
}
this->GetClientRect(&r);
this->InvalidateRect(&r);
}