470,870 Members | 2,072 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

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:
Expand|Select|Wrap|Line Numbers
  1. // MyForm.cpp
  3. void CMyForm::OnBnClickedButtonok()
  4. {
    CTP1Doc *pDoc = (CTP1Doc *)GetDocument();
  5. pDoc->hello += "BONJOUR";
  6. pDoc->UpdateAllViews(this);}
  9. // TP1View.cpp 
  11. void CTP1View::OnDraw(CDC* pDC)
  12. {
    CTP1Doc* pDoc = GetDocument();
  13. CTP1Doc* pDoc2 = GetDocument();
  14. ASSERT_VALID(pDoc);
  15. // TODO: add draw code for native data here
  16. pDC->TextOut(10,10,pDoc->hello);
  17. pDC->TextOut(10,25,pDoc2->hello2);}
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

Expand|Select|Wrap|Line Numbers
  1. //MatriceCalculs.cpp
  3. float CMatriceCalculs::VerifSolution(float *matriceA[2][2], float *matriceB[2][1])
  4. {
    CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd; 
  5. CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); 
  6. CTP1View *pView = (CTP1View *)pChild->GetActiveView();
  7. CTP1Doc *pDoc = pView->GetDocument();
  8. pDoc->hello += "// y = kekchose ";
  9. return 1.0;}
and the problem is the same, it does not update the view in real time.

Thanks for helping!
Feb 11 '08 #1
2 4714
464 Expert 256MB
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(true); or just the control area pDoc->Invalidate(true);
Feb 12 '08 #2
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!
Feb 12 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Chris Mullins | last post: by
6 posts views Thread by Robert W. | last post: by
6 posts views Thread by Greg P | last post: by
2 posts views Thread by shuisheng | last post: by
3 posts views Thread by Phung | last post: by
2 posts views Thread by =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.