Solved

Updating controls on a CFormView

Posted on 2000-03-23
12
218 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now