Solved

How to change a view from a dialog box

Posted on 1998-07-26
6
156 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

831 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