コード例 #1
0
ファイル: stdafx.cpp プロジェクト: vdrive/TrapperKeeper
HTREEITEM FindSiblingItem(const CTreeCtrl &rTree, const HTREEITEM hStartingItem, const string &rStr)
{
	HTREEITEM hItem = hStartingItem;
	while( hItem != NULL )
	{
		if( rTree.GetItemText( hItem ).Compare( rStr.c_str() ) == 0 )
			break;
		else
            hItem = rTree.GetNextSiblingItem( hItem );
	}

	return hItem;
}
コード例 #2
0
static int CALLBACK DirThenFileAplhaCB(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
    int retVal = 0;
    CTreeCtrl* pTreeCtrl = (CTreeCtrl*)lParamSort;
    
    if(pTreeCtrl != NULL)
    {
        int img1A, img1B, img2A, img2B;

        FileTreeItemData* ftidItem1 = (FileTreeItemData*)lParam1;
        FileTreeItemData* ftidItem2 = (FileTreeItemData*)lParam2;

        if((ftidItem1 != NULL) && (ftidItem2 != NULL))
        {
            HTREEITEM hItem1 = ftidItem1->hItem;
            HTREEITEM hItem2 = ftidItem2->hItem;

            if((hItem1 != NULL) && (hItem2 != NULL))
            {
                pTreeCtrl->GetItemImage(hItem1, img1A, img1B);
                pTreeCtrl->GetItemImage(hItem2, img2A, img2B);

                int folderImage = GetSysIlIndex(TEXT("\\"));

                CString itemStr1 = pTreeCtrl->GetItemText(hItem1);
                CString itemStr2 = pTreeCtrl->GetItemText(hItem2);

                if(ftidItem1->isDir && ftidItem2->isDir)
                {
                    retVal = itemStr1.CompareNoCase(itemStr2);
                }
                else if(ftidItem1->isDir)
                {
                    retVal = -1;
                }
                else if(ftidItem2->isDir)
                {
                    retVal = 1;
                }
                else
                {
                    retVal = itemStr1.CompareNoCase(itemStr2);
                }   
            }
        }
    }

    return retVal;
}
コード例 #3
0
ファイル: win32ctrlTree.cpp プロジェクト: kenkuang/pywin32
// @pymethod int|PyCTreeCtrl|GetItemText|Retrieves the text of a list view item or subitem.
PyObject *PyCTreeCtrl_GetItemText( PyObject *self, PyObject *args )
{
	PyObject *obItem;
	if (!PyArg_ParseTuple( args, "O:GetItemText",
	                   &obItem)) // @pyparm HTREEITEM|item||The item whose text is to be retrieved.
		return NULL;
	CTreeCtrl *pList = GetTreeCtrl(self);
	if (!pList) return NULL;
	HTREEITEM item;
	if (!PyWinObject_AsHANDLE(obItem, (HANDLE *)&item))
		return NULL;
 	GUI_BGN_SAVE;
	CString csText = pList->GetItemText(item);
 	GUI_END_SAVE;
	return PyWinObject_FromTCHAR(csText);
}
コード例 #4
0
ファイル: BrowseDlg.cpp プロジェクト: ardy30/tman
//
// For sorting files and dirs (dirs go before files)
//
static int CALLBACK
DirFileCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) {
	CTreeCtrl *pTreeCtrl = (CTreeCtrl *) lParamSort;
	HTREEITEM hItem1 = (HTREEITEM) lParam1;
	HTREEITEM hItem2 = (HTREEITEM) lParam2;

	int nImage1, nSelImage1;
	pTreeCtrl->GetItemImage(hItem1, nImage1, nSelImage1);
	int nImage2, nSelImage2;
	pTreeCtrl->GetItemImage(hItem2, nImage2, nSelImage2);

	if (nImage1 == ICON_DIR && nImage2 >= ICON_FILE)
		return -1;
	else if (nImage1 >= ICON_FILE && nImage2 == ICON_DIR)
		return 1;
	else {
		CString strItem1 = pTreeCtrl->GetItemText(hItem1);
		CString strItem2 = pTreeCtrl->GetItemText(hItem2);
		return strItem1.CompareNoCase(strItem2);
	}
}
コード例 #5
0
ファイル: PanelBase.cpp プロジェクト: sgajaejung/Game
HTREEITEM CPanelBase::FindTree( CTreeCtrl &treeCtrl, const wstring &findText )
{
	HTREEITEM hRoot = treeCtrl.GetRootItem();
	vector<HTREEITEM> items;
	items.reserve(treeCtrl.GetCount());

	wstring lowerText = findText;
	lowerCasew(lowerText);

	items.push_back(hRoot);

	while (!items.empty())
	{
		HTREEITEM hItem = items.back();
		items.pop_back();
		CString itemText = treeCtrl.GetItemText(hItem);
		CString lowerItemText = lowerCasew((wstring)itemText).c_str();

		const int idx = lowerItemText.Find(lowerText.c_str());
		if (idx >= 0)
			return hItem;

		HTREEITEM hfirstChild = treeCtrl.GetChildItem(hItem);
		if (hfirstChild)
		{
			items.push_back(hfirstChild);

			while (HTREEITEM hNextItem = treeCtrl.GetNextSiblingItem(hfirstChild))
			{
				items.push_back(hNextItem);
				hfirstChild = hNextItem;
			}
		}
	}

	return NULL;
}
コード例 #6
0
ファイル: SpriteListView.cpp プロジェクト: liujw/SceneEditor
void CSpriteListView::OnAddSprite()
{
	CTreeCtrl* pWndTree = (CTreeCtrl*)&m_wndSpriteView;
	ASSERT_VALID(pWndTree);

	CString strSpriteType = "";
	HTREEITEM hTreeItem = pWndTree->GetSelectedItem();
	if(hTreeItem)
	{
		strSpriteType = pWndTree->GetItemText(hTreeItem);		
	}

	CSpriteSet SpriteSetDlg(strSpriteType);
	if(SpriteSetDlg.DoModal() == IDOK)
	{
		TSpriteTree treeNode;
				
		treeNode.setName(SpriteSetDlg.m_strSurfaceName);
		treeNode.setType(SpriteSetDlg.m_strSpriteType);

		if(SpriteSetDlg.m_strFileName != "")
		{
			treeNode.setPath(SpriteSetDlg.m_strFileName);
			treeNode.setRow(SpriteSetDlg.m_nRow);
			treeNode.setCol(SpriteSetDlg.m_nCol);
		}

		g_spriteTree.addASprite(treeNode);
		m_pMainFrm = (CMainFrame *)theApp.m_pMainWnd;
		if(m_pMainFrm)
		{
			m_pMainFrm->BuildSceneTree();
			m_pMainFrm->UpdateSceneView(TRUE);
		}
	}
}
コード例 #7
0
ファイル: IISConfigHelper.cpp プロジェクト: UIKit0/IISxpress
void CIISConfigHelper::PopulateTreeFromFileSystem(CTreeCtrl& cTree, HTREEITEM htParent, const std::set<CStringW>& IgnoreDirNames, int nMaxDepth)
{
	if (htParent == NULL)
		return;	

	// get the item data from the tree item
	IISURIItem* pParentItem = (IISURIItem*) cTree.GetItemData(htParent);
	if (pParentItem == NULL)
	{
		ASSERT(pParentItem != NULL);
		return;
	}

	// if the item is incomplete then we need to get it's file system path
	if (pParentItem->Type == IISURIItem::IncompleteFileSystemPath && pParentItem->sFileSystemPath.GetLength() <= 0)
	{
		// get the grand parent item
		HTREEITEM htGrandParent = cTree.GetParentItem(htParent);
		if (htGrandParent == NULL)
		{
			ASSERT(htGrandParent != NULL);
			return;
		}		

		// get the grand parent item data
		IISURIItem* pGrandParentItem = (IISURIItem*) cTree.GetItemData(htGrandParent);
		if (pGrandParentItem == NULL)
		{
			ASSERT(pGrandParentItem != NULL);
			return;
		}

		// the grand parent MUST not be incomplete
		if (pGrandParentItem->Type == IISURIItem::IncompleteFileSystemPath)
		{
			ASSERT(pGrandParentItem->Type != IISURIItem::IncompleteFileSystemPath);
			return;
		}

		// get the item name
		CStringW sName = CStringW(cTree.GetItemText(htParent));
		if (sName.GetLength() <= 0)
		{
			ASSERT(sName.GetLength() > 0);
			return;
		}

		// make the path to the parent item
		CPathT<CStringW> ItemFileSystemPath(pGrandParentItem->sFileSystemPath);
		ItemFileSystemPath.Append(sName);

		// assign the new file system path and set the type
		pParentItem->sFileSystemPath = (LPCWSTR) ItemFileSystemPath;
		pParentItem->Type = IISURIItem::FileSystem;
	}

	// if the item already has children then we need to build up a list of their names
	std::set<CStringW> KnownDirs;
	if (cTree.ItemHasChildren(htParent) == TRUE)
	{
		// loop through all the children
		HTREEITEM htChild = cTree.GetChildItem(htParent);
		while (htChild != NULL)
		{
			// get the child name
			CStringW sName = CStringW(cTree.GetItemText(htChild));

			// we need lower case so we can compare easier
			sName.MakeLower();

			// add the name to the known list
			KnownDirs.insert(sName);

			// move on to the next child item
			htChild = cTree.GetNextSiblingItem(htChild);
		}
	}

#ifdef _DEBUG
	ATLTRACE2(L"CIISConfigHelper::PopulateTreeFromFileSystem() : searching '%s'\n", pParentItem->sFileSystemPath);
#endif

	// create a search string
	CPathT<CStringW> FileSystemPath(pParentItem->sFileSystemPath);
	FileSystemPath.Append(L"*.*");
	CStringW sSearchPath = (LPCWSTR) FileSystemPath;	

	// start the search
	WIN32_FIND_DATAW FindData;	
	HANDLE hFind = ::FindFirstFileW(sSearchPath, &FindData);
	if (hFind == INVALID_HANDLE_VALUE)
	{
		// TODO: empty
		return;
	}

	CArray<CStringW, LPCWSTR> saDirs;	

	// guess that we will have 32 sub dirs (the array will grow if we have more)
	saDirs.SetSize(32);

	// keep track of the number of dirs we have actually found
	int nDirsFound = 0;

	do
	{		
		if ((FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
			continue;		

		// eliminate . and .. from the search
		if (FindData.cFileName[0] == '.')
		{
			if (FindData.cFileName[1] == '\0')
			{
				continue;
			}
			else if (FindData.cFileName[1] == '.' && FindData.cFileName[2] == '\0')
			{
				continue;
			}
		}		
			
		// convert to lower case
		CStringW sTempFileName = FindData.cFileName;
		sTempFileName.MakeLower();

		// only add to the collection if we don't already know about it
		if (KnownDirs.find(sTempFileName) != KnownDirs.end())
			continue;

		// if it's a known ignore dir name - then ignore it
		if (IgnoreDirNames.find(sTempFileName) != IgnoreDirNames.end())
			continue;
		
#ifdef _DEBUG
		ATLTRACE2(L"CIISConfigHelper::PopulateTreeFromFileSystem() : found '%s'\n", FindData.cFileName);
#endif

		saDirs.SetAtGrow(nDirsFound, FindData.cFileName);		

		// we have found one
		nDirsFound++;
	}
	while (::FindNextFileW(hFind, &FindData) == TRUE);	

	// get rid of the find handle
	::FindClose(hFind);
	hFind = NULL;	
	
	if (nDirsFound <= 0)
	{		
		return;
	}

	if (nMaxDepth <= 0)
	{
		cTree.InsertItem(EmptyNodeString, htParent);
		return;
	}

	for (int i = 0; i < nDirsFound; i++)
	{
		CString sDir(saDirs[i]);
		HTREEITEM htChild = cTree.InsertItem(sDir, htParent);		

		// create the child file system path
		CPathT<CStringW> FileSystemPath(pParentItem->sFileSystemPath);
		FileSystemPath.Append(saDirs[i]);

		// we need an item data for this tree item
		IISURIItem* pChildItem = new IISURIItem;
		pChildItem->Type = IISURIItem::FileSystem;
		pChildItem->sFileSystemPath = (LPCWSTR) FileSystemPath;

		// make the child URI
		CStringW sChildURI = pParentItem->sURI;
		int nChildURILength = sChildURI.GetLength();
		if (nChildURILength > 0 && sChildURI[nChildURILength - 1] != '/')
			sChildURI += '/';

		// append the dir name
		sChildURI += saDirs[i];

		// assign the URI to the item data
		pChildItem->sURI = sChildURI;

		// store the item data
		cTree.SetItemData(htChild, (DWORD_PTR) pChildItem);

		PopulateTreeFromFileSystem(cTree, htChild, IgnoreDirNames, nMaxDepth - 1);
	}
}
コード例 #8
0
void CChatDlg::LoadPicFiles(CTreeCtrl& nTreeCtrl, CString nFilePath, HTREEITEM nRoot)
{

	// 判断nPicFolder是目录还是文件  
	// 如果是文件  
	//     直接将文件插入到树控件中 nTreeCtrl.InsertItem(nPicFolder,nRoot);  
	// 如果是目录  
	//     获取nPicFolder的第一层目录  
	//     判断nRoot目录下是否已经有此层目录  
	//     如果有此层目录  
	//         递归插入其他  
	//     如果无此层目录  
	//         插入此层目录,然后递归插入其他  


	CString nSubFolder;     //首层目录  
	CString nSubFilePath;   //去掉首层目录后的文件名  
	BOOL IsExist = FALSE;



	int nIndex = -1;
	nIndex = nFilePath.Find("/");

	if (nIndex >= 0) //目录  
	{
		nSubFolder = nFilePath.Left(nIndex);
		nSubFilePath = nFilePath.Right(nFilePath.GetLength() - nIndex - 1);

		HTREEITEM nSubRoot = NULL;
		if (nTreeCtrl.ItemHasChildren(nRoot))
			nSubRoot = nTreeCtrl.GetChildItem(nRoot);
		CString str;
		BOOL  bExist = FALSE;
		while (nSubRoot)
		{
			str = nTreeCtrl.GetItemText(nSubRoot);

			if (str.CompareNoCase(nSubFolder) == 0)
			{

				bExist = TRUE;
				break;
			}

			nSubRoot = nTreeCtrl.GetNextSiblingItem(nSubRoot);
		}

		if (!bExist)
		{

			nSubRoot = nTreeCtrl.InsertItem(nSubFolder, nRoot);

			LoadPicFiles(nTreeCtrl, nSubFilePath, nSubRoot);
		}
		else{
			LoadPicFiles(nTreeCtrl, nSubFilePath, nSubRoot);
		}
	}
	else 
	{
		nTreeCtrl.InsertItem(nFilePath, 1, 1, nRoot, 0);
	}
}