Solved

How to change a view from a dialog box

Posted on 1998-07-26
6
150 Views
Last Modified: 2012-05-04
Can somebody tell me how to make changes to a view from a dialog box. That is I want to draw something on a view when the some textbox data in my dialog box changes. How do i relate this textbox's (IDC_EXIT10 which is part of cConfDialog) event (ENCHANGE event?) to do something (for example draw a line) in  a view (CJLPView)?

0
Comment
Question by:jhum
  • 4
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
psdavis earned 0 total points
ID: 1168702
When creating the dialog (MFC?) pass a pointer to the view and assign it to a memory variable.

CTestDialog dlgTest;
dlgTest.m_pView = this;
dlgTest.DoModal( );

p.s. These five point questions are starting to get boring.

Phillip



0
 

Author Comment

by:jhum
ID: 1168703
Hi Phillip,

You really can't do it that way. m_pView  would point to the dlgTest instead of the view. You should store the address to the view in a variable before you declare it, something like this:

        CView* tempViewptr;
      tempViewptr=this;
      CConfDlg dlg;
      dlg.m_pView =tempViewptr;
      dlg.DoModal();

Thanks for the help and here's your boring 5 points :-)
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1168704
Ah... Not true.

The 'this' pointer is the 'this' of the calling function, such as

CView::OnConfDlg( )
{
   CConfDlg dlg;
   dlg.m_pView = this;
   dlg.DoModal( );
}

and is NOT the "this" of CConfDlg or 'dlg'.  

I Promise!  I do it all the time!  Just because the CConfDlg is created doesn't change the scope of the 'this'.  If you wanted the this of the CConfDialog, you would have to do a "dlg.this".

Phillip

0
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

 

Author Comment

by:jhum
ID: 1168705
Hi Phillip,

I tried just that . Dunno why it pointed to the dialog box. I think as soon as you declare a new instance of the dialog box, the constructor is run and therefore the 'this' pointer is already initialized. Maybe I'm wrong. More questions are sure to be on their way, and i'll try to make them more than 5 pointers :-)!

0
 
LVL 7

Expert Comment

by:psdavis
ID: 1168706
"this" is definitely the view's "this" not the dialog's "this".  I'm not sure what you're seeing!  It is true that the 'this' pointer is initialized, but it's initialized for the class that's calling it.

Cool about the points though!

Phillip



0
 
LVL 7

Expert Comment

by:psdavis
ID: 1168707
As a matter of fact, when you do a dlg.m_pView = this,  if the 'this' isn't the same class as your m_pView, then you would get a compilation error!

Phillip

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

743 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

12 Experts available now in Live!

Get 1:1 Help Now