Solved

Dialog box communication

Posted on 1998-10-08
4
154 Views
Last Modified: 2013-11-20
I down loaded a piece of code coolbar from www.codeguru.com.
It can be found at codeguru in Dockable Window/DevStudio Like CControlBar 2
It comes with a downloadable project so you can see exactly what i am trying to do.

I would like to dynamically assign the tree view its branches without doing it at Initialisation.  So i cut and pasted his code so it looks like the following.  I also made a new public function Test() that should place the branches on the tree.

Now I called the tree from the CDialogControlView file using the following code:

void CDialogControlView::ViewTest(){

TestDialog dlg;
dlg.Test();

}

The CTestDialog code is as follows:



---CUT----
BOOL CTestDialog::OnInitDialog()
{
CDialog::OnInitDialog();

CRect sz;
GetClientRect(sz);
sz.DeflateRect(5,5);

m_bInit = TRUE;


return TRUE;  // return TRUE unless you set the focus to a control
              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTestDialog::OnOK()
{
// TODO: Add extra validation here

// CDialog::OnOK();
}

void CTestDialog::Test()
{
m_Edit = (CTreeCtrl*)GetDlgItem(IDC_EDIT2);

HTREEITEM i1 = m_Edit->InsertItem("Root 1");
m_Edit->InsertItem("Branch 1", i1);
m_Edit->InsertItem("Branch 2", i1);
m_Edit->InsertItem("Branch 3", i1);
HTREEITEM i2 = m_Edit->InsertItem("Root 2");
m_Edit->InsertItem("Branch 1", i2);
m_Edit->InsertItem("Branch 2", i2);
m_Edit->InsertItem("Branch 3", i2);
HTREEITEM i3 = m_Edit->InsertItem("Root 3");
m_Edit->InsertItem("Branch 1", i3);
m_Edit->InsertItem("Branch 2", i3);
m_Edit->InsertItem("Branch 3", i3);

}

Can anyone tell me what i am doing wrong? also I am having the same problem calling CDialogControlView from CTestDialog as i keep getting assertion failures:

THe code i use for calling back is

CDialogControlView* pview;
pview->GetDocument();

this produces an assertion error.

Thanks in advance mramsay.
0
Comment
Question by:marvel
  • 2
4 Comments
 
LVL 6

Expert Comment

by:snoegler
ID: 1323122
You have to Create() or DoModal() your dialog before accessing its childs.
For example, m_Edit's m_hWnd member is NULL before you called Create() or DoModal().
I think that is your problem.
BTW: It would help more if you describe _what_ assertion you get :)
0
 
LVL 7

Accepted Solution

by:
psdavis earned 400 total points
ID: 1323123
void CDialogControlView::ViewTest()
{
   TestDialog dlg;
   dlg.Test();
}

OK, now you've lost all of your setup since after the 'Test' function is run, the object is deleted from the stack.  You can't do it this way!

void CTestDialog::Test()
{
m_Edit = (CTreeCtrl*)GetDlgItem(IDC_EDIT2);

HTREEITEM i1 = m_Edit->InsertItem("Root 1");
m_Edit->InsertItem("Branch 1", i1);
m_Edit->InsertItem("Branch 2", i1);
m_Edit->InsertItem("Branch 3", i1);
HTREEITEM i2 = m_Edit->InsertItem("Root 2");
m_Edit->InsertItem("Branch 1", i2);
m_Edit->InsertItem("Branch 2", i2);
m_Edit->InsertItem("Branch 3", i2);
HTREEITEM i3 = m_Edit->InsertItem("Root 3");
m_Edit->InsertItem("Branch 1", i3);
m_Edit->InsertItem("Branch 2", i3);
m_Edit->InsertItem("Branch 3", i3);
}

This won't work either.  GetDlgItem(IDC_EDIT2) doesn't exist yet.  It HAS to be done no earlier than in OnInitDialog!

Instead, it should look more like this...

void CDialogControlView::ViewTest()
{
   TestDialog dlg;
   dlg.DoModal( );
}

void CTestDialog::OnInitDialog()
{
  CDialog::OnInitDialog( );
  CTreeCtrl* pTreeEdit = (CTreeCtrl*)GetDlgItem(IDC_EDIT2);

  HTREEITEM i1 = pTreeEdit->InsertItem("Root 1");
  pTreeEdit->InsertItem("Branch 1", i1);
.
}

and it should appear correctly!

Phillip


0
 
LVL 7

Expert Comment

by:psdavis
ID: 1323124
> Can anyone tell me what i am doing wrong? also I am having the same problem calling CDialogControlView from CTestDialog as i keep getting assertion failures: The code i use for calling back is

> CDialogControlView* pview;
> pview->GetDocument();

Of course this won't work! What is your pview set to.  In this case, it's nothing!! it's null!! it's zip!!

If you want to pass a document pointer to your dialog, then do so during the initialization.  Try this.  Add a document pointer to the dialog's header file.  Something like

CDialogControlDoc* m_pDoc;

In your dialog's constructor...

m_pDoc = NULL;

and when you create your dialog...

void CDialogControlView::ViewTest()
{
   TestDialog dlg;
   dlg.m_pDoc = GetDocument( );
   dlg.Test();
}

Then you can call your functions much more effectively...

CTestDialog::DoSomething( )
{
   m_pDoc->DoSomethingInDoc( );
}

Phillip
0
 

Author Comment

by:marvel
ID: 1323125
close... but i found another solution
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

20 Experts available now in Live!

Get 1:1 Help Now