Solved

Dialog box communication

Posted on 1998-10-08
4
157 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 160
VBA "SendKeys" Syntax for Multiple Keystrokes 7 108
matchUp  challenge 9 108
Excel file not created as expected 7 72
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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