带有复选框的树控件,展开操作,选中复选框操作,图标操作。
BOOL CSelectOnLineNode::OnInitDialog()
{
CDialog::OnInitDialog();
AFX_MANAGE_STATE(AfxGetStaticModuleState());
///*if (!AfxOleInit())
//{
// AfxMessageBox(_T("AfxOleInit 失败!"));
//}*/
// 创建图像列表
iconList.Create(16,16,ILC_COLOR32|ILC_MASK, 0, 0);
//m_objBOMTree.SetImageList(&iconList, TVSIL_NORMAL);
// 获取对象厂
pobjFactory = pobjSession->GetObjFactory();
// 获取查询管理器
pobjQManager = pobjSession->GetQMManager();
pMetaInfo = pobjSession->GetMetaInfo();
// 将“关于...”菜单项添加到系统菜单中。
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
return TRUE; // 除非将焦点设置到控件,否则返回TRUE
}
int iIndex;
HICON hIcon = (HICON)pResultElementPtr->GetClass()->GetSmallIcon();
iIndex = iconList.Add(hIcon);
m_objBOMTree.SetImageList(&iconList, TVSIL_NORMAL);
HTREEITEM NODEX;
NODEX = m_objBOMTree.InsertItem(pResultElementPtr->ExpressName,iIndex,iIndex,NULL TVI_SORT);
CString str = _T("");
CString *str1 = new CString;
CString str2;
str = (LPTSTR)pResultElementPtr->ClassID;
str2 = (LPTSTR)pResultElementPtr->ObjectID;
*str1 = str +_T("||") + str2;
m_objBOMTree.SetItemData(NODEX,(DWORD)str1);
void CSelectOnLineNode::OnTvnItemexpandingQdTree(NMHDR *pNMHDR, LRESULT *pResult)
{
//LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
//::CPoint point;
//
//NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
//TVITEMW* pNew=&(pNMTreeView->itemNew);
//HTREEITEM htem = pNew->hItem;
///*GetCursorPos(&point);
//m_objBOMTree.ScreenToClient(&point);
//UINT uFlags;
//HTREEITEM htem;
//htem = m_objBOMTree.HitTest(point,&uFlags);*/
//
//if (htem != NULL)
//{
// /*HTREEITEM nodec = m_objEBOMSelect.GetChildItem(htem);
// while(nodec != NULL)
// {
// m_objEBOMSelect.DeleteItem(nodec);
//
// nodec = m_objEBOMSelect.GetNextSiblingItem(nodec);
// }*/
//
// CString *str = new CString;
// CString strMsg;
// IOb_ObjectPtr pobj = NULL;
// str =(CString*) m_objBOMTree.GetItemData(htem);
// CString strFlag;
// CString strValue = _T("");
// strFlag = *str;
// strTostr.Lookup(strFlag,strValue);
// if (strValue != _T(""))
// {
// return;
// }
//
// CString strClssID = _T("");
// CString strObjectID = _T("");
// int ii;
// ii = strFlag.Find(_T("||"),0);
// strClssID = strFlag.Left(strFlag.GetLength() - ii - 2);
// strObjectID = strFlag.Right(strFlag.GetLength() - ii - 2);
// // 获取该对象,并挂接其下的自对象
// pobj = pobjFactory->GetObject((LPCTSTR)strClssID, (LPCTSTR)strObjectID);
// if(pobj != NULL)
// {
// strTostr.SetAt(strFlag,strFlag);
// AddViewObject(pobj,htem,&strMsg);
// }
// //AfxMessageBox(m_objEBOMSelect.GetItemText(htem),NULL,NULL);
//}
*pResult = 0;
}
void CSelectOnLineNode::OnNMClickQdTree(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
BOOL isChecked ;
::CPoint point;
IElementDefinePtr objEleDef;
CString strGYClassID;
// 获取工艺文件的CLASSID,用于快速的定位所选定的节点是否为工艺文件节点
objEleDef = pMetaInfo->FindElementDefineByName((LPCTSTR)(strGYClassInName));
strGYClassID = (LPCTSTR)objEleDef->ClassID;
GetCursorPos(&point);
m_objBOMTree.ScreenToClient(&point);
UINT uFlags;
HTREEITEM htem;
htem = m_objBOMTree.HitTest(point,&uFlags);
m_objBOMTree.SelectItem(htem);
// 区分是选择选择框还是单击了树节点学习
if (uFlags & TVHT_ONITEMSTATEICON)
{
isChecked = !m_objBOMTree.GetCheck(htem);
CString *str = new CString;
CString strMsg;
IOb_ObjectPtr pobj = NULL;
str =(CString*) m_objBOMTree.GetItemData(htem);
CString strFlag;
CString strValue = _T("");
strFlag = *str;
AfxMessageBox(strFlag,NULL,NULL);
CString strClssID = _T("");
CString strObjectID = _T("");
int ii;
ii = strFlag.Find(_T("||"),0);
strClssID = strFlag.Left(strFlag.GetLength() - ii - 2);
strObjectID = strFlag.Right(strFlag.GetLength() - ii - 2);
// 如果节点被选中,则将相应的节点的ID加入到集合中
if (isChecked == TRUE)
{
// 判断当前选定的节点是否为工艺文件节点
if (strGYClassID == strClssID )
{
// 如果是工艺文件将其添加到其中
objTostr.SetAt(strFlag,strFlag);
}
else
{
// 不是工艺文件节点,那边遍历其下的所有的工艺文件节点,将其选中
//
SelectChildNode(htem);
}
}
else
{
// 没有选中是判断当前是否为工艺文件节点,如果为工艺文件节点
// 则要将其从集合中删除
if (strGYClassID == strClssID)
{
objTostr.Lookup(strFlag,strValue);
if (strValue != _T(""))
{
objTostr.RemoveKey(strFlag);
}
}
}
}
//delete str;
*pResult = 0;
}
// 循环选中子节点
void CSelectOnLineNode::SelectChildNode(HTREEITEM htem)
{
HTREEITEM hParentNode;
hParentNode = htem;
IElementDefinePtr objEleDef;
CString strGYClassID;
// 获取工艺文件的CLASSID,用于快速的定位所选定的节点是否为工艺文件节点
objEleDef = pMetaInfo->FindElementDefineByName((LPCTSTR)(strGYClassInName));
strGYClassID = (LPCTSTR)objEleDef->ClassID;
// 获取子节点
if(!m_objBOMTree.ItemHasChildren(hParentNode))
{
return;
}
HTREEITEM hNextItem = m_objBOMTree.GetChildItem(hParentNode);
while(hNextItem != NULL)
{
m_objBOMTree.SetCheck(hNextItem,TRUE);
CString *str = new CString;
CString strFlag;
CString strValue;
str =(CString*) m_objBOMTree.GetItemData(hNextItem);
strFlag = *str;
/*strTostr.SetAt(strFlag,strFlag);*/
CString strClssID = _T("");
CString strObjectID = _T("");
int ii;
ii = strFlag.Find(_T("||"),0);
strClssID = strFlag.Left(strFlag.GetLength() - ii - 2);
strObjectID = strFlag.Right(strFlag.GetLength() - ii - 2);
// 判断是否为工艺文件
if (strClssID == strGYClassID)
{
objTostr.Lookup(strFlag,strValue);
if (strValue == _T(""))
{
objTostr.SetAt(strFlag,strFlag);
}
}
SelectChildNode(hNextItem);
hNextItem = m_objBOMTree.GetNextSiblingItem(hNextItem);
}