CMyPictLeft::CMyPictLeft() { //CTreeView::OnInitialUpdate(); HTREEITEM parent; parent=GetTreeCtrl().InsertItem ("MARC数据",0,0); GetTreeCtrl().InsertItem ("格式化数据",0,0,parent); GetTreeCtrl().InsertItem ("出错数据",1,1,parent); GetTreeCtrl().InsertItem ("重复数据",2,2,parent); // TODO: Add your specialized code here and/or call the base class}出现非法操作
书上是这样写的可是我只用CTreeView类继承没有控件 CTreeCtrl* pCtrl = (CTreeCtrl*) GetDlgItem(IDC_TREE1); ASSERT(pCtrl != NULL);// Insert a root item using the structure. We must // initialize a TVINSERTSTRUCT structure and pass its // address to the call. TVINSERTSTRUCT tvInsert; tvInsert.hParent = NULL; tvInsert.hInsertAfter = NULL; tvInsert.item.mask = TVIF_TEXT; tvInsert.item.pszText = _T("United States");HTREEITEM hCountry = pCtrl->InsertItem(&tvInsert);// Insert subitems of that root. Pennsylvania is // a state in the United States, so its item will be a child // of the United States item. We won't set any image or states, // so we supply only the TVIF_TEXT mask flag. This // override provides nearly complete control over the // insertion operation without the tedium of initializing // a structure. If you're going to add lots of items // to a tree, you might prefer the structure override // as it affords you a performance win by allowing you // to initialize some fields of the structure only once, // outside of your insertion loop.HTREEITEM hPA = pCtrl->InsertItem(TVIF_TEXT, _T("Pennsylvania"), 0, 0, 0, 0, 0, hCountry, NULL);// Insert the "Washington" item and assure that it is // inserted after the "Pennsylvania" item. This override is // more appropriate for conveniently inserting items with // images.HTREEITEM hWA = pCtrl->InsertItem(_T("Washington"), 0, 0, hCountry, hPA);// We'll add some cities under each of the states. // The override used here is most appropriate // for inserting text-only items.pCtrl->InsertItem(_T("Pittsburgh"), hPA, TVI_SORT); pCtrl->InsertItem(_T("Harrisburg"), hPA, TVI_SORT); pCtrl->InsertItem(_T("Altoona"), hPA, TVI_SORT);pCtrl->InsertItem(_T("Seattle"), hWA, TVI_SORT); pCtrl->InsertItem(_T("Kalaloch"), hWA, TVI_SORT); pCtrl->InsertItem(_T("Yakima"), hWA, TVI_SORT);
http://www.vchelp.net/source/source_wnd_common.htm
{
CTreeView::OnInitialUpdate();
HTREEITEM parent;
parent=GetTreeCtrl().InsertItem ("MARC数据",0,0);
item1=GetTreeCtrl().InsertItem ("格式化数据",0,0,parent);
item2=GetTreeCtrl().InsertItem ("出错数据",1,1,parent);
item3=GetTreeCtrl().InsertItem ("重复数据",2,2,parent);
// TODO: Add your specialized code here and/or call the base class
}
{
GetTreeCtrl().InsertItem ("root1",0,0);
GetTreeCtrl().InsertItem ("root2",0,0);
}
出现非法操作
{
//CTreeView::OnInitialUpdate();
HTREEITEM parent;
parent=GetTreeCtrl().InsertItem ("MARC数据",0,0);
GetTreeCtrl().InsertItem ("格式化数据",0,0,parent);
GetTreeCtrl().InsertItem ("出错数据",1,1,parent);
GetTreeCtrl().InsertItem ("重复数据",2,2,parent);
// TODO: Add your specialized code here and/or call the base class}出现非法操作
CTreeCtrl* pCtrl = (CTreeCtrl*) GetDlgItem(IDC_TREE1);
ASSERT(pCtrl != NULL);// Insert a root item using the structure. We must
// initialize a TVINSERTSTRUCT structure and pass its
// address to the call. TVINSERTSTRUCT tvInsert;
tvInsert.hParent = NULL;
tvInsert.hInsertAfter = NULL;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = _T("United States");HTREEITEM hCountry = pCtrl->InsertItem(&tvInsert);// Insert subitems of that root. Pennsylvania is
// a state in the United States, so its item will be a child
// of the United States item. We won't set any image or states,
// so we supply only the TVIF_TEXT mask flag. This
// override provides nearly complete control over the
// insertion operation without the tedium of initializing
// a structure. If you're going to add lots of items
// to a tree, you might prefer the structure override
// as it affords you a performance win by allowing you
// to initialize some fields of the structure only once,
// outside of your insertion loop.HTREEITEM hPA = pCtrl->InsertItem(TVIF_TEXT,
_T("Pennsylvania"), 0, 0, 0, 0, 0, hCountry, NULL);// Insert the "Washington" item and assure that it is
// inserted after the "Pennsylvania" item. This override is
// more appropriate for conveniently inserting items with
// images.HTREEITEM hWA = pCtrl->InsertItem(_T("Washington"),
0, 0, hCountry, hPA);// We'll add some cities under each of the states.
// The override used here is most appropriate
// for inserting text-only items.pCtrl->InsertItem(_T("Pittsburgh"), hPA, TVI_SORT);
pCtrl->InsertItem(_T("Harrisburg"), hPA, TVI_SORT);
pCtrl->InsertItem(_T("Altoona"), hPA, TVI_SORT);pCtrl->InsertItem(_T("Seattle"), hWA, TVI_SORT);
pCtrl->InsertItem(_T("Kalaloch"), hWA, TVI_SORT);
pCtrl->InsertItem(_T("Yakima"), hWA, TVI_SORT);