Solved

How to change a view from a dialog box

Posted on 1998-07-26
6
159 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
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!

 

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

735 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