-
October 13th, 2011, 10:28 AM
#1
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
-
October 13th, 2011, 10:41 AM
#2
Re: mfc ASSERT(::IsWindow(m_hWnd)) issue, not sure what's wrong
- Where is the SetMyDoc called from and when?
Originally Posted by Lucky75
Code:
LONG myDialog::OnInitDialog(UINT wParam, LONG lParam)
{
BOOL bRet = super::OnInitDialog();
What is super?
Victor Nijegorodov
-
October 13th, 2011, 10:50 AM
#3
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.
-
October 13th, 2011, 11:19 AM
#4
Re: mfc ASSERT(::IsWindow(m_hWnd)) issue, not sure what's wrong
Originally Posted by Lucky75
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
-
October 13th, 2011, 11:28 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|