Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Updating controls on a CFormView

Posted on 2000-03-23
12
230 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.

792 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