Solved

Updating controls on a CFormView

Posted on 2000-03-23
12
226 Views
Last Modified: 2013-11-20
I have an app that is based on Doc/View, and also several other classes namely, CBugsWorld, CBug and CGrid.  I also have two views, the main view (CView) created by MFC and another view CInfoView (VformView). In the document header I have a public variable  CBugsWorld Bugworld.

In CView OnTimer I call a method of the CBugsWorld class through the document  ie.

CDocument* pDoc = GetDocument();
pDC->Bugworld.method(blah blah);

When some variables in the CBugsWorld class or any class it includes change, I would like to update some labels in the CInfoView view.

When I tried to add member variables for the labels to CInfoView throuogh ClassWizard, it does not list the Labels in the Member variables pane.

I know this can be done manually and it is not the main concern.  The main concern is that I don't know how the Doc/View interacts.

I would like someone to give instructions of the steps I need to perform in order to update controls (of whathever kind) in the CInfoView as well some dialogs I have.  I simply don't understand the theory of the Doc/View and seems complex.

I can handle dialogs, classes etc except the doc/view paradigm

Thanks.
0
Comment
Question by:gbzhhu
  • 3
  • 3
  • 2
  • +3
12 Comments
 
LVL 5

Expert Comment

by:vachooho
ID: 2651571
call UpdateAllViews() from inside document to update all attached views

or use directly
YourViewClass->Invalidate();
YourViewClass->UPdateWindow();
0
 
LVL 5

Expert Comment

by:vachooho
ID: 2651576
doc/view archuitecture is very simple
documnet contains all data you need and handle its serialization.

View responsible for data viewing.
It contains member function GetDocument() which return attached to view document's pointer.
View must get data from document and show it in the window.
0
 
LVL 30

Expert Comment

by:Axter
ID: 2652008
What types of controls are you trying to update?
When you say it does not list the labels in the Members variable pane, do you mean it doesn't list the "Control ID's" or do you mean it doesn't list a variable member associated with the Control ID's?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 12

Author Comment

by:gbzhhu
ID: 2652430
Axter

It does not list the Cotrol ID's so I cannot associate a member variable with them.

As for vachooho,

>>call UpdateAllViews() from inside document to update all attached views

when does the document know that its data is has changed.  Do I use SetModifiedFlags fucntion everytime a variable changes value.  My classes cannot do that since they do not know about the document.

What should I do?

Thanks
0
 
LVL 12

Expert Comment

by:migel
ID: 2652715
Hi!
You can use this;
CDocument* pDoc = GetDocument();
pDC->Bugworld.method(blah blah);
pDoc->UpdateAllViews(this);
0
 
LVL 3

Expert Comment

by:ghimireniraj
ID: 2653631
gbzhhu ,

Did you try migel idea?
It should work.
If it doesn't that means your CInfoView
doesnot yet correspond to your Document
Class.

Add to your CInfoView class header

#include " you docfile.h"

public:
CTesttestDoc* GetDocument();


IN your CInfoView implementation cpp

add method

CTesttestDoc* CInfoView::GetDocument() //
{
      ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CYourDoc)));
      return (CYourDoc*)m_pDocument;
}

Then, wher ever you use

CDocument* pDoc = GetDocument();
pDC->Bugworld.method(blah blah);

Your doc data is changed
-------------------------
 then call

pDoc->UpdateAllViews(this);

must work

niraj










0
 
LVL 4

Expert Comment

by:pagladasu
ID: 2653989
>It does not list the Cotrol ID's so I cannot associate a member variable with them.
I think you are using Static controls as referred by you as labels. Change the Control IDs of each from the default IDC_STATIC to something like IDC_STATIC1 and IDC_STATIC2. That would make them visible to ClassWizard.
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 2655860
No, I am not using static controls.  My controls have proper names.  class wizrad cannot still see them somehow!!

I have now implemented the control updating problem and that is half my problem fixed.  The points (100) for this will go to vachooho (first to point me to the right direction).  Since I have partly solved the problem (manually inserting everything without classwizard) I will ask an easy (I hope for you) for the rest of the points (100)

Ok.  When my app starts, it starts with an initial doc.  I don't know if this window is the child frame or the main frame.  But I would like to (the intial doc and all docs afterwards) to open as maximised so they fill the MDI client area.

Thanks
0
 
LVL 3

Expert Comment

by:ghimireniraj
ID: 2656786
Override the create  function for the CMDChildFrame derived class.

set the style   dwstyle====>as you like
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 2657208
ghimireniraj,

I tried your suggestion and it does not work for me.  I also tried to override PreCreate function and change dwstyle and that does  not work for me.
0
 
LVL 5

Accepted Solution

by:
vachooho earned 200 total points
ID: 2657291
MDIMaximize(MDIGetActive());
 on CMainWnd;
0
 
LVL 12

Expert Comment

by:migel
ID: 2657809
Hi!
Override the create  function for the CMDChildFrame derived class.
set the
cs.style |= WS_VISIBLE|WS_MAXIMIZE;
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand to include initial dialog with two choices. 9 78
unable to delete all specified values regedit 38 413
modThree challenge 4 90
NotAlone Challenge 20 83
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question