mfc view not updating

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • YouPoP
    New Member
    • Jun 2007
    • 17

    mfc view not updating

    Hi, I am doing an MFC MDI application with VS 8.0. I am using the default document view plus a formview ans show both of them in the view using a splitter.
    In the formview there is an event onBtnclicked that displays some valued entered by the user in the document. Here is the code in my formview:
    Code:
    // MyForm.cpp
    
    void CMyForm::OnBnClickedButtonok()
    {[INDENT]CTP1Doc *pDoc = (CTP1Doc *)GetDocument();
    pDoc->hello += "BONJOUR";
    pDoc->UpdateAllViews(this);[/INDENT]
    }
    
    
    // TP1View.cpp 
    
    void CTP1View::OnDraw(CDC* pDC)
    {[INDENT]CTP1Doc* pDoc = GetDocument();
    CTP1Doc* pDoc2 = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    pDC->TextOut(10,10,pDoc->hello);
    pDC->TextOut(10,25,pDoc2->hello2);[/INDENT]
    }
    the application is updating the view (and drawing the text) only after the application itself has been hidden (under another application, or minimized) and showing again.

    Also, i tried doing it in a third class

    Code:
    //MatriceCalculs.cpp
    
    float CMatriceCalculs::VerifSolution(float *matriceA[2][2], float *matriceB[2][1])
    {[INDENT]CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd; 
    CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); 
    CTP1View *pView = (CTP1View *)pChild->GetActiveView();
    CTP1Doc *pDoc = pView->GetDocument();
    pDoc->hello += "// y = kekchose ";
    return 1.0;[/INDENT]
    }
    and the problem is the same, it does not update the view in real time.

    Thanks for helping!
  • Studlyami
    Recognized Expert Contributor
    • Sep 2007
    • 464

    #2
    you need to invalidate the object after you have finished updating it (this will make a call to OnPaint()). You can invalidate the entire object this->Invalidate(tru e); or just the control area pDoc->Invalidate(tru e);

    Comment

    • YouPoP
      New Member
      • Jun 2007
      • 17

      #3
      pDoc->Invalidate(tru e);
      is not working (Invalidate not a member of TP1Doc)
      but Invalidate() in the OnUpdate method is working fine

      thank you very much for your reply!

      Comment

      Working...