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);
}
...全文
405 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
真糨糊 2006-04-28
  • 打赏
  • 举报
回复
在MSDN里
BOOL CreateEx( DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hwndParent, HMENU nIDorHMenu, LPVOID lpParam = NULL );

BOOL CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, LPVOID lpParam = NULL);


lpszClassName

Points to a null-terminated character string that names the Windows class (aWNDCLASS structure). The class name can be any name registered with the global AfxRegisterWndClass function or any of the predefined control-class names. It must not be NULL.

类名不能为空
真糨糊 2006-04-28
  • 打赏
  • 举报
回复
这样创建
CYFTipWnd wnd;
wnd.CreateEx(NULL,AfxRegisterWndClass(CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, AfxGetApp()->LoadStandardCursor(IDC_ARROW),
(HBRUSH)::GetStockObject(NULL_BRUSH)), NULL,WS_VISIBLE | WS_POPUP|WS_CLIPCHILDREN,CRect(0,0,300,200),this,NULL);
xqk 2006-04-28
  • 打赏
  • 举报
回复
加我QQ我帮你解决:
QQ:9955511
yrb 2006-04-28
  • 打赏
  • 举报
回复
换一下提问的方式:
从CWnd派生一个窗口,并且显示(显示为弹出窗口或显示为一个窗口的子窗口,正确的做法是?
yrb 2006-04-28
  • 打赏
  • 举报
回复
创建和使用以上窗口的代码:

//创建tip窗口
this->m_YFTipWnd.CreateEx(
WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
NULL,
NULL,
WS_BORDER | WS_POPUP,
CRect(0, 0, 0, 0),
NULL,
0);
this->m_YFTipWnd.ShowWindow(SW_SHOWNORMAL);


//在需要的地方显示tip窗口
CPoint pt2;
pt2.x = rcClient.left;
pt2.y = this->m_AdjustingPos;
this->ClientToScreen(&pt2);
this->m_YFTipWnd.SetWindowPos(&wndTop, pt2.x, pt2.y, 0, 0, WP_NOACTIVATE | SWP_SHOWWINDOW);


//设置提示内容
this->m_YFTipWnd.SetContent(s);


handsomerun 2006-04-28
  • 打赏
  • 举报
回复
跟踪看一下,执行到哪出现这个错误,这样,调试起来快很多

15,975

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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