各位大哥,我快被老板开除了!请问如何用TreeView做一个和Windows一模一样的驱动器列表?倾囊求解,UP有分,一定要救我! 如何用TreeView做一个和Window一模一样的驱动器列表?哪位大哥有这个程序给我一个也行告诉我也行,救命呀!!!要有各种图标(驱动器、应用程序。)算法要求点开哪个目录再进行搜索,以加快运行速度。我知道怎么做以后再开贴给分! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HRESULT SHGetFolderPath( HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath); mfc window程序设计 中有这种例子, 完整的代码哦!!!我发给你,但是你的邮箱呢? visual c++MFC扩展编程里面有一个很类似的例子。你可以参考一下,在那个基础上再改进估计就可以了。 先去网上搜索吧。www.codeguru.comwww.codeproject.comwww.mindcracker.comwww.vckbase.com...要是还不行我看开除的一点也不冤。说得直了一点,不过公司开人不一定是公司不对,你说对不对? 你说的就是windows里面资源管理器界面吧?那在我上面提到的例子43:创建资源管理器界面中有详细介绍和代码。 LPITEMIDLIST SHBrowseForFolder( LPBROWSEINFO lpbi); visual c++MFC扩展编程这本书我没有,你把代码发给我吧MFC我有,但是代码实现的功能不够,thanks a lot! // test.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"int _tmain(int argc, _TCHAR* argv[]){ TCHAR szPath[MAX_PATH]={0}; BROWSEINFO bi = {0}; bi.hwndOwner = GetConsoleWindow(); bi.lpszTitle = "Get it1"; LPITEMIDLIST p = SHBrowseForFolder(&bi); SHGetPathFromIDList( p,szPath); printf(szPath); getchar(); return 0;}// stdafx.h : 标准系统包含文件的包含文件,// 或是常用但不常更改的项目特定的包含文件//#pragma once#define _WIN32_WINNT 0x0500#define WINVER 0x0500//#define WIN32_LEAN_AND_MEAN // 从 Windows 头中排除极少使用的资料#include <windows.h>#include <shlobj.h>#pragma comment(lib,"shell32.lib")#include <stdio.h>#include <tchar.h>// TODO: 在此处引用程序要求的附加头 我先给你个十分简单的Tree,方便你储存信息然后告诉你如何得到磁盘信息,使用CFileFinder最后关于图标,在VC的安装目录下可以找得到//...MyTree.h#include <vector>#include <iostream.h>using namespace std;template <class T>class CTreeNode{public: vector<int> m_ChildIndex; T m_Value; int m_Index; int m_ParentsIndex; // Root's m_ParentIndex=-1};template <class T>class CMyTree{protected: vector<CTreeNode<T>*> m_Nodes;public: int CreateRoot(T Value); // return Root's index,always it is 0,if return -1,that is there is a root already. int AddChild(int ParentIndex,T Value); // return the child node's index. if return -1,that is there is no root int RemoveChild(int iIndex); T GetAt(int Index); int GetCount(); void RemoveAll(); };template <class T>int CMyTree<T>::CreateRoot(T Value){ if(m_Nodes.size()>0) return -1; CTreeNode<T>* pNode=new CTreeNode<T>; pNode->m_Value=Value; pNode->m_ParentsIndex=-1; pNode->m_Index=0; m_Nodes.push_back(pNode); return pNode->m_Index;}template <class T>int CMyTree<T>::AddChild(int ParentIndex,T Value){ CTreeNode<T>* pNode=new CTreeNode<T>; CTreeNode<T>* pParentNode; if(m_Nodes.size()==0) { delete pNode; return -1; } if(ParentIndex<0 || ParentIndex>(int)m_Nodes.size()-1) { delete pNode; return -2; } pNode->m_Value=Value; pNode->m_ParentsIndex=ParentIndex; pNode->m_Index=(int)m_Nodes.size(); pParentNode=m_Nodes.at(ParentIndex); pParentNode->m_ChildIndex.push_back(pNode->m_Index); m_Nodes.push_back(pNode); return pNode->m_Index;}template <class T>T CMyTree<T>::GetAt(int Index){ if(Index<0 || Index>(int)m_Nodes.size()-1) return NULL; CTreeNode<T>* pNode=m_Nodes.at(Index); return pNode->m_Value;}template <class T>int CMyTree<T>::GetCount(){ return (int)m_Nodes.size();}template <class T>void CMyTree<T>::RemoveAll(){ m_Nodes.empty();}template <class T>void CMyTree<T>::RemoveChild(int iIndex){}看看这个程序使用的CFileFind就知道了#include <afxwin.h>#include <iostream>using namespace std;void Recurse(LPCTSTR pstr){ CFileFind finder; // build a string with wildcards CString strWildcard(pstr); strWildcard += _T("\\*.*"); // start working for files BOOL bWorking = finder.FindFile(strWildcard); while (bWorking) { bWorking = finder.FindNextFile(); // skip . and .. files; otherwise, we'd // recur infinitely! if (finder.IsDots()) continue; // if it's a directory, recursively search it if (finder.IsDirectory()) { CString str = finder.GetFilePath(); cout << (LPCTSTR) str << endl; Recurse(str); } } finder.Close();}void main(){ if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0)) cout << "panic!" << endl; else Recurse(_T("C:"));} 留下你的E-mail,我发源码给你! [email protected]谢谢各位大哥了! 我用的是BCB如果可以,给你一个类似的程序,另外,好象用线程的方法展开节点速度较快:P 如果没记错的话,《visual c++高级编程范例》里面有一摸一样的范例,去书店找找吧。 在vc中实现图像在鼠标的拖动下移动!急~~在线等! 注入的DLL如何调用宿主函数? 请教DLL的问题,在线等…… 关于模板类pair的问题,请大虾帮助!! 请问哪里可以下w2k源码 请教1个问题,我使用Shell_NotifyIcon 函数为程序制作了1个任务栏图标,但如何在关闭程序时把它去掉呢 请微软技术支持回答 mfc 抓屏问题 C++ Builder &&&& Visual C++ 那个更好一些? http://www.csdn.net/expert/topic/187/187757.shtm,谁帮忙解答一下,高分酬谢!! ListBox控件问题(小问题) 我是新手,怎么学VC++
HRESULT SHGetFolderPath(
HWND hwndOwner,
int nFolder,
HANDLE hToken,
DWORD dwFlags,
LPTSTR pszPath
);
你可以参考一下,在那个基础上再改进估计就可以了。
www.codeguru.com
www.codeproject.com
www.mindcracker.com
www.vckbase.com...要是还不行我看开除的一点也不冤。说得直了一点,不过公司开人不一定是公司不对,你说对不对?
那在我上面提到的例子43:创建资源管理器界面
中有详细介绍和代码。
LPBROWSEINFO lpbi
);
MFC我有,但是代码实现的功能不够,thanks a lot!
//#include "stdafx.h"int _tmain(int argc, _TCHAR* argv[])
{
TCHAR szPath[MAX_PATH]={0};
BROWSEINFO bi = {0};
bi.hwndOwner = GetConsoleWindow();
bi.lpszTitle = "Get it1";
LPITEMIDLIST p = SHBrowseForFolder(&bi);
SHGetPathFromIDList( p,szPath);
printf(szPath);
getchar();
return 0;
}
// stdafx.h : 标准系统包含文件的包含文件,
// 或是常用但不常更改的项目特定的包含文件
//#pragma once
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
//#define WIN32_LEAN_AND_MEAN // 从 Windows 头中排除极少使用的资料
#include <windows.h>
#include <shlobj.h>
#pragma comment(lib,"shell32.lib")
#include <stdio.h>
#include <tchar.h>// TODO: 在此处引用程序要求的附加头
然后告诉你如何得到磁盘信息,使用CFileFinder
最后关于图标,在VC的安装目录下可以找得到
//...MyTree.h#include <vector>
#include <iostream.h>
using namespace std;template <class T>
class CTreeNode
{
public:
vector<int> m_ChildIndex;
T m_Value;
int m_Index;
int m_ParentsIndex; // Root's m_ParentIndex=-1
};template <class T>
class CMyTree
{
protected:
vector<CTreeNode<T>*> m_Nodes;
public:
int CreateRoot(T Value); // return Root's index,always it is 0,if return -1,that is there is a root already.
int AddChild(int ParentIndex,T Value); // return the child node's index. if return -1,that is there is no root
int RemoveChild(int iIndex);
T GetAt(int Index);
int GetCount();
void RemoveAll();
};template <class T>
int CMyTree<T>::CreateRoot(T Value)
{
if(m_Nodes.size()>0)
return -1;
CTreeNode<T>* pNode=new CTreeNode<T>;
pNode->m_Value=Value;
pNode->m_ParentsIndex=-1;
pNode->m_Index=0;
m_Nodes.push_back(pNode);
return pNode->m_Index;
}template <class T>
int CMyTree<T>::AddChild(int ParentIndex,T Value)
{ CTreeNode<T>* pNode=new CTreeNode<T>;
CTreeNode<T>* pParentNode;
if(m_Nodes.size()==0)
{
delete pNode;
return -1;
}
if(ParentIndex<0 || ParentIndex>(int)m_Nodes.size()-1)
{
delete pNode;
return -2;
} pNode->m_Value=Value;
pNode->m_ParentsIndex=ParentIndex;
pNode->m_Index=(int)m_Nodes.size();
pParentNode=m_Nodes.at(ParentIndex);
pParentNode->m_ChildIndex.push_back(pNode->m_Index); m_Nodes.push_back(pNode);
return pNode->m_Index;
}template <class T>
T CMyTree<T>::GetAt(int Index)
{
if(Index<0 || Index>(int)m_Nodes.size()-1)
return NULL;
CTreeNode<T>* pNode=m_Nodes.at(Index);
return pNode->m_Value;
}template <class T>
int CMyTree<T>::GetCount()
{
return (int)m_Nodes.size();
}template <class T>
void CMyTree<T>::RemoveAll()
{
m_Nodes.empty();
}template <class T>
void CMyTree<T>::RemoveChild(int iIndex)
{
}看看这个程序使用的CFileFind就知道了#include <afxwin.h>
#include <iostream>using namespace std;void Recurse(LPCTSTR pstr)
{
CFileFind finder; // build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T("\\*.*"); // start working for files
BOOL bWorking = finder.FindFile(strWildcard); while (bWorking)
{
bWorking = finder.FindNextFile(); // skip . and .. files; otherwise, we'd
// recur infinitely! if (finder.IsDots())
continue; // if it's a directory, recursively search it if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
cout << (LPCTSTR) str << endl;
Recurse(str);
}
} finder.Close();
}void main()
{
if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0))
cout << "panic!" << endl;
else
Recurse(_T("C:"));
}
谢谢各位大哥了!