在文件中存储的是树型结构的数据,
读出来后,我想在程序里保存到一个树型结构当中(不是树型控件)
这个树型结构应该怎样做
读出来后,我想在程序里保存到一个树型结构当中(不是树型控件)
这个树型结构应该怎样做
解决方案 »
- VS2010 MFC 默认生成 ActiveX工程,编译出的ocx文件,为什么不能用
- 导入JPG文件资源的问题
- 透明对话框实现窗口拖拉改变大小?
- MFC中对话框和单文档的"退出"有什么不同?
- 类似OutLook的界面,如何对右侧的视图进行生成和切换?请大家帮忙!
- 如何在视图类中响应对话框按钮单击事件?
- 在线程控制函数里如何获得当前线程的句柄或者对象?
- 用QuartzCore,在layer上用CGContextDrawImage描画图像,放大时出现黑条
- vc环境里的宏如$(ProjectDir)如何修改路径内容,能不能自己也定义一个?
- 用CString类在屏幕显示的问题.
- 按下控制键(Ctrl)怎么写?
- HOOK API大家都来讨论一下,能说多少算多少!
{
tagITEM * item;
char * name;
int (*func)();
int image;
int simage;
} Item;
item:树的其他分支的指针(如果没有为NULL) name:该结点显示在树控制中的字符串 func:在树控制上双击该结点是执行函数的指针 image:该结点使用的图象列表的索引 simage:该接点被选中时使用的图象列表的索引 使用例子:int substring1()
{
AfxMessageBox("substring1");
return 0;
}int substring2()
{
AfxMessageBox("substring2");
return 0;
}int string2()
{
AfxMessageBox("string2");
return 0;
}Item BRANCH1[] =
{
{NULL, "SubString1", substring1, 0, 0},
{NULL, "SubString2", substring2, 0, 0},
{NULL, "", NULL, 0, 0}
};Item root[] =
{
{NULL, "String1", NULL, 0, 0}, // Root node with a branch on it
{BRANCH1, NULL, NULL, 0, 0}, // Another Item array for the branch
{NULL, "String2", string2, 1, 1}, // Single node.
{NULL, "", NULL, 0, 0} // last element - needed for the loading function to tell when it's at the last node.
};
加载时,我使用的递归方法:void CTestView::InsertData(HTREEITEM parent, Item * item)
{
HTREEITEM newparent;while(item->name != "") // while we are not at the last member of the structure
{
if(item->item == NULL) // if this is a parent node
{
// Insert the item into the tree
newparent = m_pTree->InsertItem(
TVIF_IMAGE|TVIF_PARAM|TVIF_SELECTEDIMAGE|TVIF_STATE|TVIF_TEXT,
item->name,
item->image,
item->simage,
(item->func == NULL ? TVIS_BOLD : NULL),
TVIS_BOLD,
(LPARAM)item->func,
parent,
TVI_LAST);
}
else
{
InsertData(newparent, item->item); // call this function again with the new structure
}item++; // go to the next member of the array
}
}