Solved

Dialog box communication

Posted on 1998-10-08
4
171 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
[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
  • 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

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!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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