예제 #1
0
HTREEITEM CDirectoryTreeCtrl::AddChildItem(HTREEITEM hRoot, CString strText)
{
	CString strDir = GetFullPath(hRoot);

	strDir += strText;
	if (hRoot == NULL)
		strDir += _T('\\');

	TV_INSERTSTRUCT	itInsert;
	SHFILEINFO		shFinfo;

	memzero(&itInsert, sizeof(itInsert));
	
	if ( SHGetFileInfo( strDir, FILE_ATTRIBUTE_DIRECTORY, &shFinfo, sizeof(shFinfo),
		SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES ) != NULL )
	{
		itInsert.item.mask |= TVIF_IMAGE;
		itInsert.item.iImage = shFinfo.iIcon;
	}
	
	if ( SHGetFileInfo( strDir, FILE_ATTRIBUTE_DIRECTORY, &shFinfo, sizeof(shFinfo),
		SHGFI_SYSICONINDEX | SHGFI_OPENICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES ) != NULL )
	{
		itInsert.item.mask |= TVIF_SELECTEDIMAGE;
		itInsert.item.iSelectedImage = shFinfo.iIcon;
	}

	if (hRoot != NULL)
		strDir += _T('\\');

	if (HasSharedSubdirectory(strDir))
		itInsert.item.state = TVIS_BOLD;

	if (HasSubdirectories(strDir))
		itInsert.item.cChildren = 1;		// used to display the + symbol next to each item

	itInsert.item.mask |= TVIF_CHILDREN | TVIF_HANDLE | TVIF_TEXT | TVIF_STATE;
	itInsert.item.stateMask = TVIS_BOLD;
	itInsert.item.pszText = const_cast<LPTSTR>(strText.GetString());
	itInsert.hInsertAfter = (hRoot == NULL) ? TVI_LAST : TVI_SORT;	// root items are already sorted
	itInsert.hParent = hRoot;

	HTREEITEM hItem = InsertItem(&itInsert);

	if (IsShared(strDir))
		SetCheck(hItem);

	return hItem;
}
HTREEITEM CDirectoryTreeCtrl::AddChildItem(HTREEITEM hRoot, CString strText)
{
	CString strPath = GetFullPath(hRoot);
	if (hRoot != NULL && strPath.Right(1) != _T("\\"))
		strPath += _T("\\");
	CString strDir = strPath + strText;
	TV_INSERTSTRUCT itInsert;
//==>optimizer added [shadow2004]
#ifdef OPTIM
	memzero(&itInsert, sizeof(itInsert));
#else //OPTIM
	memset(&itInsert, 0, sizeof(itInsert));
#endif //OPTIM
//<==optimizer added [shadow2004]
	
	// START: changed by FoRcHa /////
	WORD wWinVer = thePrefs.GetWindowsVersion();
	if(wWinVer == _WINVER_2K_ || wWinVer == _WINVER_XP_ || wWinVer == _WINVER_ME_)		
	{
		itInsert.item.mask = TVIF_CHILDREN | TVIF_HANDLE | TVIF_TEXT |
							TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
		itInsert.item.stateMask = TVIS_BOLD | TVIS_STATEIMAGEMASK;
	}
	else
	{
		itInsert.item.mask = TVIF_CHILDREN | TVIF_HANDLE | TVIF_TEXT | TVIF_STATE;
		itInsert.item.stateMask = TVIS_BOLD;
	}
	// END: changed by FoRcHa ///////
	
	if (HasSharedSubdirectory(strDir))
		itInsert.item.state = TVIS_BOLD;
	else
		itInsert.item.state = 0;
	if (HasSubdirectories(strDir))
		itInsert.item.cChildren = I_CHILDRENCALLBACK;		// used to display the + symbol next to each item
	else
		itInsert.item.cChildren = 0;

	itInsert.item.pszText = strText.GetBuffer();
	itInsert.item.cchTextMax = strText.GetLength();
	itInsert.hInsertAfter = hRoot ? TVI_SORT : TVI_LAST;
	itInsert.hParent = hRoot;
	
	// START: added by FoRcHa ////////////////
	if(wWinVer == _WINVER_2K_ || wWinVer == _WINVER_XP_ || wWinVer == _WINVER_ME_)		
	{
		CString strTemp = strDir;
		if(strTemp.Right(1) != _T("\\"))
			strTemp += _T("\\");
		
		UINT nType = GetDriveType(strTemp);
		if(DRIVE_REMOVABLE <= nType && nType <= DRIVE_RAMDISK)
			itInsert.item.iImage = nType;
	
		SHFILEINFO shFinfo;
		shFinfo.szDisplayName[0] = _T('\0');
		if(!SHGetFileInfo(strTemp, 0, &shFinfo,	sizeof(shFinfo),
						SHGFI_ICON | SHGFI_SMALLICON | SHGFI_DISPLAYNAME))
		{
			TRACE(_T("Error Gettting SystemFileInfo!"));
			itInsert.itemex.iImage = 0; // :(
		}
		else
		{
			itInsert.itemex.iImage = shFinfo.iIcon;
			DestroyIcon(shFinfo.hIcon);
			if (hRoot == NULL && shFinfo.szDisplayName[0] != _T('\0'))
			{
				STreeItem* pti = new STreeItem;
				pti->strPath = strText;
				strText = shFinfo.szDisplayName;
				itInsert.item.pszText = strText.GetBuffer();
				itInsert.item.cchTextMax = strText.GetLength();
				itInsert.item.mask |= TVIF_PARAM;
				itInsert.item.lParam = (LPARAM)pti;
			}
		}

		if(!SHGetFileInfo(strTemp, 0, &shFinfo, sizeof(shFinfo),
							SHGFI_ICON | SHGFI_OPENICON | SHGFI_SMALLICON))
		{
			TRACE(_T("Error Gettting SystemFileInfo!"));
			itInsert.itemex.iImage = 0;
		}
		else
		{
			itInsert.itemex.iSelectedImage = shFinfo.iIcon;
			DestroyIcon(shFinfo.hIcon);
		}
	}
	// END: added by FoRcHa //////////////

	HTREEITEM hItem = InsertItem(&itInsert);
	if (IsShared(strDir))
		SetCheck(hItem);
	strText.ReleaseBuffer();

	return hItem;
}