Temporal position of pMainFrame->LoadFrame & DialogBar Control Updates...
-
Hello, This is a continuation of my earlier question. I've reposted because I have more information and my previous post was a bit misleading. I found that my application crashes during the "LoadFrame" statement below located in MyApp.cpp. // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; It seems that my DialogBar's controls are updating themselves before LoadFrame returns and the next statement executes (m_pMainWnd = pMainFrame). When these controls update, I'm trying to get information from the (MDI) Document to fill them, and the program crashes upon the execution of the following CDialogBar code (because m_pMainWnd is null at the time): CGoalsDoc* pDoc = (CGoalsDoc*)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument(); Why are my controls trying to update (e.g., OnKillFocusEditBox1) before the main frame has been created and "m_pMainWnd" has a value? Is there an easy way around this? I don't think I monkeyed with the MFC Wizard too much, but I may have changed something small, yet important. Thanks! JennyP
-
Hello, This is a continuation of my earlier question. I've reposted because I have more information and my previous post was a bit misleading. I found that my application crashes during the "LoadFrame" statement below located in MyApp.cpp. // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; It seems that my DialogBar's controls are updating themselves before LoadFrame returns and the next statement executes (m_pMainWnd = pMainFrame). When these controls update, I'm trying to get information from the (MDI) Document to fill them, and the program crashes upon the execution of the following CDialogBar code (because m_pMainWnd is null at the time): CGoalsDoc* pDoc = (CGoalsDoc*)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument(); Why are my controls trying to update (e.g., OnKillFocusEditBox1) before the main frame has been created and "m_pMainWnd" has a value? Is there an easy way around this? I don't think I monkeyed with the MFC Wizard too much, but I may have changed something small, yet important. Thanks! JennyP
Does
m_pMainWnd = new CMainFrame();
if ( !static_cast < CMainFrame* > (m_pMainWnd)->LoadFrame(IDR_MAINFRAME) )
{
return FALSE;
}work? This way you have a non-NULL
m_pMainWnd
beforeLoadFrame()
executes. Alternatively, you can wrap your GetActiveDocument call in aif (initialised)
clause and set a bool initialised to true after you have loaded the MainFrame. "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert Kaminski -
Does
m_pMainWnd = new CMainFrame();
if ( !static_cast < CMainFrame* > (m_pMainWnd)->LoadFrame(IDR_MAINFRAME) )
{
return FALSE;
}work? This way you have a non-NULL
m_pMainWnd
beforeLoadFrame()
executes. Alternatively, you can wrap your GetActiveDocument call in aif (initialised)
clause and set a bool initialised to true after you have loaded the MainFrame. "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert KaminskiAfter some more time, I found the issue (loosely related): After deleting a control from my dialog, VC++ assigned the first tab stop to a edit control. I handle the kill-focus message for this edit box and this handler crashes the program because it tries to access the document directly. Therefore, the fix was to change my tab order so that THIS control was not the first. Good lesson, but it took too much time to debug for me. :( :) JennyP