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

x
?
Solved

Dialog box communication

Posted on 1998-10-08
4
Medium Priority
?
182 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 1600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

916 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