-
August 18th, 2007, 03:03 PM
#1
Using Create with a tree control, having problems
I'm sure I'm missing something, but I am learning VC++ on my own here. It seems like every time I try something new, I spend 10 hours tracking down something stupid. Basically this is a button that opens up a property tree control, or dialog, I don't know. Using this here: http://www.codeproject.com/treectrl/proptree.asp
Code:
BOOL CSPec::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD dwStyle;
CRect rc;
// PTS_NOTIFY - CPropTree will send notification messages to the parent window
dwStyle = WS_CHILD|WS_VISIBLE|PTS_NOTIFY;
// Init the control's size to cover the entire client area
GetClientRect(rc);
// Create CPropTree control
Tree.Create(dwStyle, rc, this, IDC_PROPERTYTREE); //Here is the problem
//
// Create some tree items
//
// Create a root item (root items should always be CPropTreeItem object since they
// can not have properties
CPropTreeItem* pRoot;
pRoot = Tree.InsertItem(new CPropTreeItem());
pRoot->SetLabelText(_T("Properties"));
pRoot->SetInfoText(_T("This is a root level item"));
pRoot->Expand(); // have this item expanded by default
// Create a static item
CPropTreeItem* pItem;
pItem = Tree.InsertItem(new CPropTreeItem(), pRoot);
pItem->SetLabelText(_T("Sub Item"));
pItem->SetInfoText(_T("This is a simple subitem"));
// Create a dropdown combolist box
CPropTreeItemCombo* pCombo;
pCombo = (CPropTreeItemCombo*)Tree.InsertItem(new CPropTreeItemCombo(), pRoot);
pCombo->SetLabelText(_T("Combo Item"));
pCombo->SetInfoText(_T("This is a TRUE/FALSE dropdown combo list"));
pCombo->CreateComboBoxBool(); // create the ComboBox control and auto fill with TRUE/FALSE values
pCombo->SetItemValue(TRUE); // set the combo box to default as TRUE
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CSPec::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
Tree.DeleteAllItems();
Tree.DestroyWindow();
return CDialog::DestroyWindow();
}
I've tried various combinations of using PostNcDestroy, delete Tree vs. DestroyWindow, etc. And all I do is get crashes on the Create line after I close the dialog and open it again. As if it's not really deleting anything or something, and it's trying to access something that doesn't exist. I don't know. This is very frustrating though. :/ Any ideas, or obvious idiocy on my part? Should I just get over it and switch to VB?
-
August 19th, 2007, 04:18 PM
#2
Re: Using Create with a tree control, having problems
Are you creating a new instance of your dialog class each time? Dialogs are not normally closed with DestroyWindow but with EndDialog. Also when a parent window is destroyed its child windows are automatically destroyed before it, but your parent is trying to destruct its child window before it is itself being destroyed.
-
August 20th, 2007, 09:46 AM
#3
Re: Using Create with a tree control, having problems
1. Have you tried stepping into the code that crashes in the debugger? Is it a crash or an Assert?
2. What version of the compiler are you using? The source for that control indicates that it was compatible for Visual Studio 6.0 and Visual Studio 2003.
Gort...Klaatu, Barada Nikto!
-
August 20th, 2007, 07:54 PM
#4
Re: Using Create with a tree control, having problems
Originally Posted by NMTop40
Dialogs are not normally closed with DestroyWindow but with EndDialog. Also when a parent window is destroyed its child windows are automatically destroyed before it, but your parent is trying to destruct its child window before it is itself being destroyed.
That is not entirely correct. To dismiss modal dialogs, code should call EndDIalog. Modeless dialogs should call DestroyWindow from OnOK handler.
Originally Posted by NMTop40
Also when a parent window is destroyed its child windows are automatically destroyed before it, but your parent is trying to destruct its child window before it is itself being destroyed.
Assuming destroying child window before parent is destroyed, should not create any problems, unless added code does something unexpected.
IxiterraConsider posting entire project. Zip only project, source and res files.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|