C++ CTreeCtrl 树结构 非递归读取

有时需要,非递归实现,否则不好查它的上级是哪个;

 

typedef struct ContentStruct
{
	string key;
	string value;
}PARAM_CONTENT_STRUCT;

typedef struct ParamStruct
{
	string section;
	vector content;
}PARAM_STRUCT;


vector m_paramList;

bool CTreeCtrlDlg::ReadTreeCtrlAllData(CTreeCtrl& _ctrl)
{
	bool ret = false;
	HTREEITEM hItem = _ctrl.GetRootItem();
	CString itmData;

	if (NULL == hItem)
	{
		return ret;
	}

	if (!_ctrl.ItemHasChildren(hItem))
	{
		return ret;
	}

	m_Rwconfig.m_paramList.clear();
	hItem = _ctrl.GetChildItem(hItem);

	do
	{
		PARAM_STRUCT param;

		itmData = _ctrl.GetItemText(hItem);
		param.section = itmData;

		if (_ctrl.ItemHasChildren(hItem))
		{
			HTREEITEM name_hItem = _ctrl.GetChildItem(hItem);
			do{

				PARAM_CONTENT_STRUCT content;
				itmData = _ctrl.GetItemText(name_hItem);
				content.key = itmData;

				if (_ctrl.ItemHasChildren(name_hItem))
				{
					HTREEITEM subhItem = _ctrl.GetChildItem(name_hItem);
					itmData = _ctrl.GetItemText(subhItem);
					content.value = itmData;
				}

				param.content.push_back(content);
			} while (name_hItem = _ctrl.GetNextSiblingItem(name_hItem));
		}
		m_Rwconfig.m_paramList.push_back(param);
	} while (hItem = _ctrl.GetNextSiblingItem(hItem));

	return true;
}

 

你可能感兴趣的:(C/C++)