CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    89

    Debug Assertion Failed!!


    In MFC, i called m_dlgInstance.Invalidate before i destroy the current window by calling
    CDialog::OnOK, this gives me a debug assertion failed message.



    void CScsetting::OnOK()
    {
    // TODO: Add extra validation here
    ...............
    ...............
    CAdminDlg m_admindlg;
    if XXXX
    {
    m_admindlg.Invalidate();
    CDialog::OnOK //Debug Assertion Failed here!!!!!!!!!!!

    }
    else
    {
    .........

    CDialog::OnOK;
    }
    }




    I must do a Invalidate() to force the main window which is in CAdminDlg to repaint when the current
    dialog box destroyed. But then i faced a debug assertion failed if i do a Invalidate for the main window before
    i call CDialog::OnOK.

    anybody can help me??


  2. #2
    Join Date
    May 1999
    Location
    UK
    Posts
    59

    Re: Debug Assertion Failed!!

    You shouldn't need the Invalidate() call. The OS will detect which areas of the screen need repainted when your dialog gets destroyed. Your call is marking the dialog needing repainted, then your destroy it, so when Windows tries to post you WM_PAINT I bet that's the ASSERT (hWnd not valid or some such thing?).

    MJA

  3. #3
    Join Date
    May 1999
    Location
    Yerevan, Armenia
    Posts
    147

    Re: Debug Assertion Failed!!

    Hi

    Debug assertion failed because you are calling Invalidate method for C++ object wich does not contain REAL Windows object (they are not same) inside. For CDialog derived objects you must call DoModal() or Create() methods to create REAL Dialog.Only after then you can call Invalidate() method . But...

    As I understand you alraedy have REAL CAdminDlg object (your main window). And you'd like to call Invalidate() method for this existing object. Then you must do

    1. add a member variable to CScsetting class
    CAdminDlg * m_admindlg; // pointer to CAdminDlg
    2 . CScsetting class constructor
    CScsetting:: CScsetting (CWnd *parent)
    {
    m_admindlg=parent;
    .........
    .........
    }
    3. Pass to CScsetting class constructor adress of existing CAdminDlg object. If you are creating CScsetting object in CAdminDlg member function then
    CScsetting dlg(this);
    dlg.DoModal ;

    4. In CScsetting::OnOK() remove line
    CAdminDlg m_admindlg; // ERROR !!!!!!!!!!!
    and call
    m_admindlg->Invalidate(); // instead of m_admindlg.Invalidate();

    It will work

    Regards

    Zorik Galstyan


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured