mfc ASSERT(::IsWindow(m_hWnd)) issue, not sure what's wrong
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: mfc ASSERT(::IsWindow(m_hWnd)) issue, not sure what's wrong

  1. #1
    Join Date
    Apr 2007
    Posts
    87

    mfc ASSERT(::IsWindow(m_hWnd)) issue, not sure what's wrong

    I'm having a bug in my code that's kicking my ***, so after much attempted debugging I finally decided to see if anyone else knew what my issue was.

    I'm trying to add a grid object to a dialog that I have, but I keep hitting the assert in the title and I don't know why.

    Code:
    LONG myDialog::OnInitDialog(UINT wParam, LONG lParam)
    {
        BOOL bRet = super::OnInitDialog();
    
        InitGridControl();
        InitLayout();
    
        myApp.ActiveDocChangeEvent->Attach(
        RefMemberDelegate1(*this, &myDialog::OnNewDoc), this); //attach to event so I know when document is created
    
        return bRet;
    }
    
    void myDialog::OnNewDoc(CDerivedDocument* pNewDoc)
    {
        pNewDoc->SetMyDialog(this); // when new document is created, set pointer to dialog
    }
    
    void myDialog::InitGridControl()
    {
        CRect rect;
        // Get the grid area rectangle and set it up.
        GetDlgItem(IDC_GRID)->GetClientRect(rect);
        GetDlgItem(IDC_GRID)->MapWindowPoints(this, &rect); //replacing dummy image with the grid
    
        m_Grid = new myGridCtrl;
        bool result = m_Grid->Create(WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP, rect, this, IDC_GRID);
    
    
        // Set the appropriate options 
        //...options...
    
        m_Grid->InsertColumn(0, _T("Name"), 100); //doesn't seem to crash here, which means grid is creted okay?
    
    }
    
    
    void myDialog::PopulateGridControl(BOOL bRedraw, CDerivedDocument * pDoc)
    {
    
        if(GetSafeHwnd() == NULL)
            return;
    
    
        //get handles to document and stuff
    
        m_Grid->SetRedraw(FALSE); // ASSERTS HERE
        m_Grid->RemoveAll();
    
        //other stuff
    }
    
    
    /////////////////////
    
    
    //In CDocument once it is created...
    
    CDerivedDocument::SetMyDoc(myDialog * pDlg)
    {
        pDlg->PopulateGridControl(true,this);
    }
    Any idea what's going on? I mean, I only create the dialog once everything has been initalized, so there shouldn't be a problem there. m_Grid.Create() returns true, so creation is successful. Why is SetRedraw() hitting the assert that the m_hWnd isn't a handle to a window? Where does m_hWnd get set anyway?

    Thanks for any help you can offer.

    Cheers

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,277

    Re: mfc ASSERT(::IsWindow(m_hWnd)) issue, not sure what's wrong

    1. Where is the SetMyDoc called from and when?
    2. Quote Originally Posted by Lucky75
      Code:
      LONG myDialog::OnInitDialog(UINT wParam, LONG lParam)
      {
          BOOL bRet = super::OnInitDialog();
      What is super?
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2007
    Posts
    87

    Re: mfc ASSERT(::IsWindow(m_hWnd)) issue, not sure what's wrong

    Super is just a pointer to the parent class. Not sure what you mean by when "SetMyDoc" is called. Never? I get a pointer to the doc from the callback by attaching to an "ActiveDocChangeEvent" which then calls OnNewDoc with the pointer to the document.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,423

    Re: mfc ASSERT(::IsWindow(m_hWnd)) issue, not sure what's wrong

    Quote Originally Posted by Lucky75 View Post
    I'm having a bug in my code that's kicking my ***, so after much attempted debugging I finally decided to see if anyone else knew what my issue was.
    So what is the value of m_hWnd? That's the one piece of information lacking from your posts, given the title of this thread.

    Is it NULL, or an obvious bogus window handle value?

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Apr 1999
    Posts
    27,423

    Re: mfc ASSERT(::IsWindow(m_hWnd)) issue, not sure what's wrong

    I only create the dialog once everything has been initalized, so there shouldn't be a problem there. m_Grid.Create() returns true, so creation is successful
    Well, you can test your assumptions by issuing the same call that MFC is issuing, right at the end of m_Grid.Create():
    Code:
    ASSERT(::IsWindow(m_hWnd));
    If the assert is triggered, then your assumptions are not correct.
    Where does m_hWnd get set anyway?
    You can test when a variable changes by using the special breakpoint set up that only gets hit on changed variables. See the Breakpoint menu. Just give it the address of the m_hWnd variable, run the program, and the program will break if the value of m_hWnd changes (thus you will know when it gets set).

    Regards,

    Paul McKenzie

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center