//************************************ // 函数名称: SetItemExpand // 返回类型: void // 参数信息: bool _Expanded // 参数信息: CTreeNodeUI * _TreeNode // 函数说明: //************************************ void CTreeViewUI::SetItemExpand( bool _Expanded,CTreeNodeUI* _TreeNode /*= NULL*/ ) { if(_TreeNode) { if(_TreeNode->GetCountChild() > 0) { int nCount = _TreeNode->GetCountChild(); for(int nIndex = 0;nIndex < nCount;nIndex++) { CTreeNodeUI* pItem = _TreeNode->GetChildNode(nIndex); pItem->SetVisible(_Expanded); if(pItem->GetCountChild() && !pItem->GetFolderButton()->IsSelected()) SetItemExpand(_Expanded,pItem); } } } else { int nIndex = 0; int nCount = GetCount(); while(nIndex < nCount) { CTreeNodeUI* pItem = (CTreeNodeUI*)GetItemAt(nIndex); pItem->SetVisible(_Expanded); if(pItem->GetCountChild() && !pItem->GetFolderButton()->IsSelected()) SetItemExpand(_Expanded,pItem); nIndex++; } } }
//************************************ // 函数名称: SetItemCheckBox // 返回类型: bool // 参数信息: bool _Selected // 参数信息: CTreeNodeUI * _TreeNode // 函数说明: //************************************ bool CTreeViewUI::SetItemCheckBox( bool _Selected,CTreeNodeUI* _TreeNode /*= NULL*/ ) { if(_TreeNode) { if(_TreeNode->GetCountChild() > 0) { int nCount = _TreeNode->GetCountChild(); for(int nIndex = 0;nIndex < nCount;nIndex++) { CTreeNodeUI* pItem = _TreeNode->GetChildNode(nIndex); pItem->GetCheckBox()->Selected(_Selected); if(pItem->GetCountChild()) SetItemCheckBox(_Selected,pItem); } } return true; } else { int nIndex = 0; int nCount = GetCount(); while(nIndex < nCount) { CTreeNodeUI* pItem = (CTreeNodeUI*)GetItemAt(nIndex); pItem->GetCheckBox()->Selected(_Selected); if(pItem->GetCountChild()) SetItemCheckBox(_Selected,pItem); nIndex++; } return true; } return false; }
//************************************ // 函数名称: RemoveAt // 返回类型: bool // 参数信息: int iIndex // 函数说明: iIndex 索引以及下的所有节点将被一并移除 //************************************ bool CTreeViewUI::RemoveAt( int iIndex ) { CTreeNodeUI* pItem = (CTreeNodeUI*)GetItemAt(iIndex); if(pItem->GetCountChild()) Remove(pItem); return true; }
// 【建议】直接在播放列表里嵌入一个listbox控件来存放文件路径,这样操作起来就方便多了。 // 由于没有Demo可以参考,所以为了让大家知道treeview的更多用法,这里用treeview作为示例。 void CDuiFrameWnd::GetPlaylistInfo(int &iIndexTreeStart, int &iFileCount) { iIndexTreeStart = -1; iFileCount = 0; // 查找路径文件的起始节点,目前为nodePlaylist第3个子节点 CTreeNodeUI *pNodeTmp; CTreeNodeUI *pNodePlaylist = static_cast<CTreeNodeUI*>(m_PaintManager.FindControl(_T("nodePlaylist"))); int iNodeTotal = pNodePlaylist->GetCountChild(); int i; for(i = 0; i < iNodeTotal; i++) { pNodeTmp = pNodePlaylist->GetChildNode(i); if (U_TAG_PLAYLIST == pNodeTmp->GetTag()) { break; } } // 未找到U_TAG_PLAYLIST的子节点,说明没有文件加入 if (i == iNodeTotal) { return; } // 已找到起始节点,开始找上一个文件或下一个文件 CTreeViewUI* pTree = static_cast<CTreeViewUI*>(m_PaintManager.FindControl(_T("treePlaylist"))); if (pTree) { iIndexTreeStart = pTree->GetItemIndex(pNodeTmp); iFileCount = iNodeTotal - i; } }
IMPL_LUA_FUNC(LuaCTreeNodeUI, GetCountChild) { try { CTreeNodeUI* self; self = static_cast<CTreeNodeUI*>(LuaStatic::CheckUserData(l, 1)); lua_pushinteger(l,self->GetCountChild()); return 1; } catch (...) { DuiException(_T("LuaCTreeNodeUI::GetCountChild")); return 0; } }
void CLoginDlg::OnPrepare(TNotifyUI& msg) { __super::OnPrepare(msg); CControlUI* pControl = m_PaintManager.FindControl("maxbtn"); if(pControl) pControl->SetVisible(false); CCheckBoxUI* pCheckBox = (CCheckBoxUI*)m_PaintManager.FindControl("autologin"); //pCheckBox->SetCheck(true); static CMyBrowserEventHandler eventhandle; CWebBrowserUI* m_pbrowserSpList = static_cast<CWebBrowserUI*>(m_PaintManager.FindControl(_T("ie"))); if (m_pbrowserSpList) { m_pbrowserSpList->SetWebBrowserEventHandler(&eventhandle); m_pbrowserSpList->Navigate2("about:blank"); PostMessage(WM_MSG_SET_FOCUS); // m_pbrowserSpList->Navigate2("http://www.baidu.com"); } CWebBrowserUI* m_pbrowserSpList1 = static_cast<CWebBrowserUI*>(m_PaintManager.FindControl(_T("ie2"))); if (m_pbrowserSpList1) { m_pbrowserSpList1->SetWebBrowserEventHandler(&eventhandle); m_pbrowserSpList1->Navigate2("http://www.baidu.com"); } CListUI *list = static_cast<CListUI*>(m_PaintManager.FindControl(_T("listex"))); list->SetKeyboardEnabled(false); //³õʼ»¯Ê÷µÄÏÔʾ CTreeViewUI* pTree = static_cast<CTreeViewUI*>(m_PaintManager.FindControl(_T("tree"))); if (!pTree) { return; } pControl = m_PaintManager.FindControl(_T("drag")); pTree->m_pDragingCtrl = pControl; CTreeNodeUI* pNodeRoot = new CTreeNodeUI; pNodeRoot->SetAttribute(_T("folderattr"),_T("padding=\"0,1,0,0\" width=\"36\" height=\"16\" normalimage=\"file='treeview_b.png' source='0,0,36,16'\" hotimage=\"file='treeview_b.png' source='36,0,72,16'\" selectedimage=\"file='treeview_a.png' source='0,0,36,16' selectedhotimage=\"file='treeview_a.png' source='36,0,72,16'\"")); pTree->Add(pNodeRoot); CDuiString strNode = ""; strNode.Format("Ö÷»úÁбí"); pNodeRoot->SetItemText(strNode); pNodeRoot->SetExpand(true); //m_pNodeRoot = pNodeRoot; for (int i = 1; i < 17; i++) { int nn = pNodeRoot->GetCountChild(); CTreeNodeUI* pNodeParent = new CTreeNodeUI; pNodeRoot->AddChildNode(pNodeParent); pNodeParent->SetName(strNode); pNodeParent->SetAttribute(_T("folderattr"),_T("padding=\"0,1,0,0\" width=\"36\" height=\"16\" normalimage=\"file='treeview_b.png' source='0,0,36,16'\" hotimage=\"file='treeview_b.png' source='36,0,72,16'\" selectedimage=\"file='treeview_a.png' source='0,0,36,16' selectedhotimage=\"file='treeview_a.png' source='36,0,72,16'\"")); CDuiString strNode = ""; strNode.Format("Ŀ¼%d", i); pNodeParent->SetItemText(strNode); pNodeParent->SetName(strNode); if (i % 4 == 0) { pNodeParent->SetExpand(true); } for (int j = 1; j< 7; j++) { CTreeNodeUI* pNodeChild = new CTreeNodeUI(true); //±íʾÊÇÒ¶×Ó½Úµã CDuiString strNode = ""; strNode.Format("%d_%d", i, j); pNodeChild->SetItemText(strNode); pNodeChild->SetName(strNode); pNodeParent->AddChildNode(pNodeChild); } } }