我在编程时遇到了一个问题:
For information on how your program can cause an  assertion  failure ,
see  the Visual C++ documention on  asserts,
(Press  Retry to debug thre application)
  终止    重试   忽略
并且在调试时中断总出现在下面语句处:
 m_wndPushButton0.Create (_T ("查看当前"), WS_CHILD | WS_VISIBLE |
       BS_DEFPUSHBUTTON, rect, this, IDC_Dangqian);
想来想去也不知道问题到底出在哪里?
由于我是一位编程新手,所以还请哪位高手能详细解答一下,非常感谢!!

解决方案 »

  1.   

    那个this是什么,必须是一个已经存在的窗口才行
      

  2.   

    m_wndPushButton0是什么类型的变量?
    IDC_Dangqian,有人已经使用它了吗?总之,多帖一些代码
      

  3.   

    要创建一个新窗口,是想用this指父窗口吧?
    最好明确指定父窗口的句柄
      

  4.   

    debug的时候出现
    For information on how your program can cause an  assertion  failure , 
    see  the Visual C++ documention on  asserts, 
    (Press  Retry to debug thre application) 
      终止    重试  忽略 
    点“重试”,看程序在哪行代码处中断。
    单从你上面的代码不太好判断具体是什么问题。
      

  5.   

    m_wndPushButton0应该是CButton类型的,
    然后m_wndPushButton0.create(,,,)要创建这个按钮,
    this指定按钮的父窗口,但是该参数是CWnd* 类型的,所以lz的this,参数类型不对
      

  6.   

    你说的很对,m_wndPushButton0就是CButton类型的, 
    并且m_wndPushButton0.create(,,,)是用来创建一个按钮, 
    this指定按钮的父窗口,原语句这样写的
    void CChildView::OnPaint() 
    {
    CPaintDC dc(this);
    CFont* pOldFont = dc.SelectObject (&m_fontMain);
        TEXTMETRIC tm;
        dc.GetTextMetrics (&tm);
        m_cxChar = tm.tmAveCharWidth;
        m_cyChar = tm.tmHeight + tm.tmExternalLeading;
        dc.SelectObject (pOldFont);
      CRect rect (m_cxChar * 2, m_cyChar, m_cxChar * 48, m_cyChar * 2);
    rect.SetRect (m_cxChar * 15, m_cyChar * 3, m_cxChar * 45,m_cyChar * 5);
        m_wndPushButton0.Create (_T ("查看当前"), WS_CHILD | WS_VISIBLE |
           BS_PUSHBUTTON, rect, this, IDC_Dangqian);
    '
    '
    '
    }
    但不知道怎样改一下比较好?还请指点一下,谢谢
      

  7.   

    谢谢!
    this指的是主窗口。
    我贴了一段程序在下面。
      

  8.   

    谢谢!
    m_wndPushButton0就是CButton类型的, 
    IDC_Dangqian 在开始我已经定义了。第一次编译
    时时好的,多编译几次就出现上面的问题。我贴了段程序在上面,你可以看一下。
      

  9.   

    CWnd *cwnd = CWnd::FromHandle(this->m_hWnd);
    用cwnd替换this试试。
      

  10.   

    不好意思,上面记错了,this也是正确的。不需要多此一举取cwnd,真不好意思。
    你的代码我 测试时没有出现问题啊。
    不过你这里面,this不是主窗口,多文档里mainframe才是主窗口
      

  11.   

    我刚试了一下。把语句改成下面样子:
    void CChildView::OnPaint() 
    {
     CPaintDC dc(this);
    CFont* pOldFont = dc.SelectObject (&m_fontMain);
        TEXTMETRIC tm;
        dc.GetTextMetrics (&tm);
        m_cxChar = tm.tmAveCharWidth;
        m_cyChar = tm.tmHeight + tm.tmExternalLeading;
        dc.SelectObject (pOldFont);
       CRect rect (m_cxChar * 2, m_cyChar, m_cxChar * 48, m_cyChar * 2);
    rect.SetRect (m_cxChar * 15, m_cyChar * 3, m_cxChar * 45,m_cyChar * 5);
        m_wndPushButton0.Create (_T ("查看当前"), WS_CHILD | WS_VISIBLE |
           BS_PUSHBUTTON, rect, this, IDC_Dangqian);
    }
    还是那个问题,
    好像有时出现竟然无法识别一个存在的头文件的问题。
    不过还是很感谢你!!就把分加给你吧。
    冒昧问一下:如果你有时间,很希望你能帮我看一下完整的程序。不知可否?
    如果不便,还请见谅!