Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

How to change a view from a dialog box

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
jhum
Asked:
jhum
  • 4
  • 2
1 Solution
 
psdavisCommented:
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
 
jhumAuthor Commented:
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
 
psdavisCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jhumAuthor Commented:
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
 
psdavisCommented:
"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
 
psdavisCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now