Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Temporal position of pMainFrame->LoadFrame & DialogBar Control Updates...

Temporal position of pMainFrame->LoadFrame & DialogBar Control Updates...

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JennyP
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • J 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

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      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 before LoadFrame() executes. Alternatively, you can wrap your GetActiveDocument call in a if (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

      J 1 Reply Last reply
      0
      • J jhwurmbach

        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 before LoadFrame() executes. Alternatively, you can wrap your GetActiveDocument call in a if (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

        J Offline
        J Offline
        JennyP
        wrote on last edited by
        #3

        After 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups