Link to home
Start Free TrialLog in
Avatar of gbzhhu
gbzhhuFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Updating controls on a CFormView

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.
Avatar of vachooho
vachooho
Flag of United States of America image

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

or use directly
YourViewClass->Invalidate();
YourViewClass->UPdateWindow();
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.
Avatar of Axter
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?
Avatar of gbzhhu

ASKER

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
Avatar of migel
migel

Hi!
You can use this;
CDocument* pDoc = GetDocument();
pDC->Bugworld.method(blah blah);
pDoc->UpdateAllViews(this);
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










>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.
Avatar of gbzhhu

ASKER

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
Override the create  function for the CMDChildFrame derived class.

set the style   dwstyle====>as you like
Avatar of gbzhhu

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of vachooho
vachooho
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi!
Override the create  function for the CMDChildFrame derived class.
set the
cs.style |= WS_VISIBLE|WS_MAXIMIZE;