Solved

How to change a view from a dialog box

Posted on 1998-07-26
6
160 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

752 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