⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 favtree.cpp

📁 myie的源程序是用VC++写自已可以扩搌使用
💻 CPP
字号:
// FavTree.cpp : implementation file
//

#include "stdafx.h"
#include "MyIE.h"
#include "FavTree.h"
#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFavTree

CFavTree::CFavTree()
{
}

CFavTree::~CFavTree()
{
	m_wndFav.m_FavTreeCtrl.DeleteAllItems();
	m_wndFav.m_FavTreeCtrl.m_astrFav.RemoveAll();

}



/////////////////////////////////////////////////////////////////////////////
// CFavTree message handlers

LPSTR CFavTree::GetTitle()
{
	strTitle.LoadString(IDS_TITLE_FAVORITE);
	return strTitle.GetBuffer(1);
}

BOOL CFavTree::Initialize()
{
	// TODO: Add your command handler code here
	CWaitCursor wc;

	CString           szPath;

	// find out from the registry where the favorites are located.
	if(!((CMainFrame*)pMainFrame)->GetFavoriteFolder(szPath))
		return FALSE;

	HTREEITEM hRoot;
	CString fstr;
	fstr.LoadString(IDS_TITLE_FAVORITE);
	hRoot = m_wndFav.m_FavTreeCtrl.InsertItem(fstr, 0, 2, NULL,TVI_FIRST);
	m_wndFav.m_FavTreeCtrl.SetItemData(hRoot, -1);

	BuildFavorites(szPath,0, hRoot);
	m_wndFav.m_FavTreeCtrl.Expand(hRoot,TVE_EXPAND);


	return TRUE;
}

BOOL CFavTree::Create(CWnd* pParent)
{
	m_wndFav.Create(NULL,NULL, WS_CHILD|WS_VISIBLE,CRect(0,0,0,0), pParent, 100);
	m_wndFav.m_FavTreeCtrl.m_pFavTree = this;
	return TRUE;
}

CWnd* CFavTree::GetWindow()
{
	return (CWnd*)&m_wndFav;
}

void CFavTree::Destroy()
{
	m_wndFav.m_FavTreeCtrl.DeleteAllItems();
	m_wndFav.m_FavTreeCtrl.m_astrFav.RemoveAll();
	return;
}


BOOL CFavTree::Update(int nLevel)
{
	m_wndFav.LockWindowUpdate();
	m_wndFav.m_FavTreeCtrl.DeleteAllItems();
	m_wndFav.m_FavTreeCtrl.m_astrFav.RemoveAll();
	Initialize();
	m_wndFav.UnlockWindowUpdate();

	return TRUE;
}

int CFavTree::BuildFavorites(LPCTSTR pszPath, int nStartPos, HTREEITEM hItem, int nLevel)
{
	CString         strPath(pszPath);
	CString         strPath2;
	CString         str,str2;
	WIN32_FIND_DATA wfd;
	HANDLE          h;
	int             nPos;
	int             nEndPos;
	int             nNewEndPos;
	int             nLastDir;
	TCHAR           buf[2048], tmp[10];
	CStringArray    astrFavorites;
	CStringArray    astrDirs;
	HTREEITEM		hnode;
	BOOL			bBest = m_wndFav.m_bBest;

	// make sure there's a trailing backslash
	if(strPath[strPath.GetLength() - 1] != _T('\\'))
		strPath += _T('\\');
	strPath2 = strPath;
	strPath += "*.*";

	// now scan the directory, first for .URL files and then for subdirectories
	// that may also contain .URL files
	h = FindFirstFile(strPath, &wfd);
	if(h != INVALID_HANDLE_VALUE)
	{
		nEndPos = nStartPos;
		do
		{
			if((wfd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM))==0)
			{
				str = wfd.cFileName;str2=str;
				str.MakeLower();
				if(str.Right(4) == _T(".url"))
				{
					tmp[0]=0;
					// an .URL file is formatted just like an .INI file, so we can
					// use GetPrivateProfileString() to get the information we want
					::GetPrivateProfileString(_T("InternetShortcut"), _T("URL"),
											  _T(""), buf, 2048,
											  strPath2 + str);
					::GetPrivateProfileString(_T("MyIE"), _T("MostFav"),
											  _T(""), tmp, 10,
											  strPath2 + str);
					str2 = str2.Left(str2.GetLength() - 4);


					// scan through the array and perform an insertion sort
					// to make sure the menu ends up in alphabetic order
					/*for(nPos = nStartPos ; nPos < nEndPos ; ++nPos)
					{
						if(str.CompareNoCase(astrFavorites[nPos]) < 0)
							break;
					}*/
					if(!bBest || (bBest && tmp[0]=='1'))
					{
						nPos = nEndPos;
						astrFavorites.InsertAt(nPos, str2);
						m_wndFav.m_FavTreeCtrl.m_astrFav.InsertAt(nPos, buf);
						++nEndPos;
					}
				}
				else  if(!bBest && str.Right(4) == _T(".lnk"))
				{
					//if(!bBest && ((CMainFrame*)pMainFrame)->ResolveLink(strPath2 + str, buf))
					{

						// scan through the array and perform an insertion sort
						// to make sure the menu ends up in alphabetic order
						/*for(nPos = nStartPos ; nPos < nEndPos ; ++nPos)
						{
							if(str.CompareNoCase(astrFavorites[nPos]) < 0)
								break;
						}*/
						nPos = nEndPos;
						m_wndFav.m_FavTreeCtrl.m_astrFav.InsertAt(nPos, strPath2 + str);
						str2 = str2.Left(str2.GetLength() - 4);
						astrFavorites.InsertAt(nPos, str2);
						++nEndPos;
					}
				}
			}
		} while(FindNextFile(h, &wfd));
		FindClose(h);
		// Now add these items to the menu
		for(nPos = nStartPos ; nPos < nEndPos ; ++nPos)
		{
			str = astrFavorites[nPos];
		//	pMenu->AppendMenu(MF_STRING | MF_ENABLED , 0xe00 + nPos, fstr);
			buf[0]=0;
			OFSTRUCT ofs;
			if(OpenFile(strPath2+str+".url", &ofs, OF_EXIST)!=HFILE_ERROR)
				::GetPrivateProfileString(_T("MyIE"), _T("MostFav"),
						  _T(""), buf, 2048,
						  strPath2 + str+".url");
			if(buf[0]!='1' && !bBest)
				hnode = m_wndFav.m_FavTreeCtrl.InsertItem(str, 1, 1, hItem,TVI_SORT);
			else if(buf[0]=='1')
				hnode = m_wndFav.m_FavTreeCtrl.InsertItem(str, 4, 4, hItem,TVI_SORT);
			m_wndFav.m_FavTreeCtrl.SetItemData(hnode, nPos);
		}


		// now that we've got all the .URL files, check the subdirectories for more
		nLastDir = 0;
		h = FindFirstFile(strPath, &wfd);
		ASSERT(h != INVALID_HANDLE_VALUE);
		CString strcha = "频道";
		CString strcha2; strcha2.LoadString(IDS_CHANNEL_E);
		HTREEITEM hLastDir=TVI_FIRST;
		do
		{
			if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				// ignore the current and parent directory entries
				if(lstrcmp(wfd.cFileName, _T(".")) == 0 || lstrcmp(wfd.cFileName, _T("..")) == 0)
					continue;

				/*for(nPos = 0 ; nPos < nLastDir ; ++nPos)
				{
					if(astrDirs[nPos].CompareNoCase(wfd.cFileName) > 0)
						break;
				}*/
				nPos = nLastDir;

				// call this function recursively.
				//	pMenu->InsertMenu(nPos, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT)pSubMenu->m_hMenu, wfd.cFileName);
				char mff[2];
				mff[0]=0;
				GetPrivateProfileString("MyIE", "MostFav", "0", mff, 2, strPath2+wfd.cFileName+"\\"+"myiefolder.mic");
				if(mff[0]=='1')
					hnode = m_wndFav.m_FavTreeCtrl.InsertItem(wfd.cFileName, 5, 6, hItem,hLastDir);
				else
					hnode = m_wndFav.m_FavTreeCtrl.InsertItem(wfd.cFileName, 0, 2, hItem,hLastDir);

				m_wndFav.m_FavTreeCtrl.SetItemData(hnode, -1);
				astrDirs.InsertAt(nPos, wfd.cFileName);
				++nLastDir;
			//	nNewEndPos = BuildFavorites(strPath2 + wfd.cFileName, nEndPos, hnode, nLevel);
			
				if((wfd.cFileName==strcha || wfd.cFileName==strcha2))//nNewEndPos == nEndPos &&
					m_wndFav.m_FavTreeCtrl.DeleteItem(hnode);
				//else if(nNewEndPos == nEndPos && bBest)
					//m_wndFav.m_FavTreeCtrl.DeleteItem(hnode);
				else
				{
					hLastDir = hnode;
					if(strPath2+wfd.cFileName+"\\" == ((CMainFrame*)pMainFrame)->m_strStartFavFolder)
					{
						m_wndFav.m_FavTreeCtrl.m_hStartFolder = hnode;
						m_wndFav.m_FavTreeCtrl.SetItemState(hnode,TVIS_BOLD,TVIS_BOLD);
					}
				}
//				nEndPos = nNewEndPos;
			}
		} while(FindNextFile(h, &wfd));
		FindClose(h);
	}


	return nEndPos;

}

/*
BOOL CFavTree::ResolveLink(LPCSTR lpszLinkFile, LPSTR lpszPath)
{

    HRESULT hres; 
    IShellLink* psl; 
    char szGotPath[MAX_PATH]; 
    char szDescription[MAX_PATH]; 
    WIN32_FIND_DATA wfd; 
 
    *lpszPath = 0; // assume failure 
 
    // Get a pointer to the IShellLink interface. 
    hres = CoCreateInstance(CLSID_ShellLink, NULL, 
        CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl); 
    if (SUCCEEDED(hres)) { 
        IPersistFile* ppf; 
        // Get a pointer to the IPersistFile interface. 
        hres = psl->QueryInterface(IID_IPersistFile, 
            (void**)&ppf); 
        if (SUCCEEDED(hres)) { 
            WCHAR wsz[MAX_PATH]; 
 
            // Ensure that the string is Unicode. 
            MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, 
                MAX_PATH); 

            // Load the shortcut. 
            hres = ppf->Load(wsz, STGM_READ); 
            if (SUCCEEDED(hres)) { 
 
               // Resolve the link. 
                hres = psl->Resolve(this->m_wndFav.m_hWnd, SLR_ANY_MATCH); 
                if (SUCCEEDED(hres)) { 
 
                    // Get the path to the link target. 
                    hres = psl->GetPath(szGotPath, 
                        MAX_PATH, (WIN32_FIND_DATA *)&wfd, 
                        SLGP_SHORTPATH ); 
                    //if (FAILED(hres)) 
                        //HandleErr(hres); // application-defined function 

                    // Get the description of the target. 
                    hres = psl->GetDescription(szDescription, MAX_PATH); 
                    //if (FAILED(hres)) 
                       // HandleErr(hres); 
                    lstrcpy(lpszPath, szGotPath); 
                } 
            } 
        // Release the pointer to the IPersistFile interface. 
        ppf->Release(); 
        } 
    // Release the pointer to the IShellLink interface. 
    psl->Release(); 
    } 
    return SUCCEEDED(hres); 

}
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -