CShellTree Version 1.02 (any previous unversioned copies are older/inferior)
Selom Ofori (SubRosa) Please see http://chat.carleton.ca/~sofori for updates and
method descriptions. Thanks to everybody who reported/fixed some of the
bugs and to those who requested features. Created with MSVC 5, tested under win95 OSR2
and WINNT 4
Anybody who is interested in having a ShellFolder tree directly in his
dialog box has probably tried to come to grips with MFCENUM. MFCENUM is pretty
easy to understand, but only if you go through the pain of trying to modify the code
to work with yours. CShellTree contains the important parts of MFCENUM that deals with
browsing the shell namespace.
CShellTree inherits CTreeCtrl. After you initialize the tree with the Shell Folders
the only other interaction the Shell 'engine' has with the tree control is through
TVN_ITEMEXPANDING (when the user clicks on the plus sign or double clicks on the folder).
Operations:
//Initializes the treeview with "mycomputer" etc
void PopulateTree();
//Initializes the treeview starting with a special folder as root
//See the SHGetSpecialFolderLocation() for constants and descriptions
void PopulateTree(int SpecialFolderID);
//Must be called from OnItemExpanding(), message TVN_ITEMEXPANDING
void OnFolderExpanding(NMHDR* pNMHDR, LRESULT* pResult);
//Frees memory allocated for the shell object. message TVN_DELETEITEM
void OnDeleteShellItem(NMHDR* pNMHDR, LRESULT* pResult);
//Must be called from OnRclick(). message NM_RCLICK
void GetContextMenu(NMHDR* pNMHDR, LRESULT* pResult);
//Must be called from OnSelChanged(), message TVN_SELCHANGED
BOOL OnFolderSelected(NMHDR* pNMHDR, LRESULT* pResult, CString &szFolderPath);
//Enables Folder Images in the tree control.
void EnableImages();
//Retrieves the path of the Selected Folder.
BOOL GetSelectedFolderPath(CString &szFolderPath);
//Opens the folder of the specified path. Does it's own error checking
void TunnelTree(CString szFindPath)
The General Steps are:
1. Include 'shelltree.cpp' and 'shelltree.h' into your project
Include 'shellpidl.cpp' and 'shellpidl.h' into your project
Include 'filename.cpp' and 'filename.h' into your project
2. Create a dialog or use an existing dialog ( after you are familar with CShellTree)
3. Add a treecontrol to your dialog.
4. Do not create member variables of the treecontrol using classwizard. Instead open the header
file of the dialog class and
#include "Shelltree.h"
then add
CShellTree* m_TreeCtl;
to the dialog class.
4b. You can make CShellTree show up in class wizard but it requires deleting your .clw file
and having classwizard rebuild the class information. Better backup your .clw file before
you decide to do this.
=============
5. In your OnInitDialog(), a callback to the WM_INITDIALOG message, initialize your treecontrol
BOOL CTreeExampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_TreeCtl = (CShellTree*) GetDlgItem(IDC_SHELLTREE); //replace IDC_SHELLTREE with your control's ID
ASSERT(m_TreeCtl);
m_TreeCtl->EnableImages(); //enable images
m_TreeCtl->PopulateTree(); //populate for the with Shell Folders for the first time
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
NOTE: REQUIRED. CShellTree handles the images for you. DO NOT attach an ImageList to CSHellTree. This internal imagelist
is a handle to the system image list and uses it directly. Using CImageList will result in the
system imagelist being destroyed after your application exits.
the call
m_TreeCtl->EnableImages();
creates and attaches an image list to the Tree Control
To initialize the ShellFolders you call
m_TreeCtl->PopulateTree();
This fills it with the starting folders like "mycomputer","network neighbourhood etc"
============
6. It is very important that you create OnItemExpanding(), a callback to TVN_ITEMEXPANDING.
Otherwise your tree would be pretty much dead.
void CTreeExampleDlg::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
m_TreeCtl->OnFolderExpanding(pNMHDR,pResult);
*pResult = 0;
}
Comments: REQUIRED. The OnFolderExpanding() method of CShellTree does the dirty work of
adding folder nodes to the tree control. It takes the same paramters as your
OnItemExpanding, so all you have to do is pass the paramters along.
==============
7. If you want a popup menu to be active, create a OnRclick(), a callback to NM_RCLICK. This
popup is the same as the one in windows explorer.
void CTreeExampleDlg::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_TreeCtl->GetContextMenu(pNMHDR,pResult);
*pResult = 0;
}
Comments: Takes the same paramters as OnRclick. All you do is pass on the parameters to
the GetContextMenu() method of CShellTree. The popup is handled by the system.
==========
8. CShellTree expects you to keep track of the filepath in your OnSelChanged(), a callback to
TVN_SELCHANGED. CShellTree provides a method
OnFolderSelected(NMHDR* pNMHDR, LRESULT* pResult, CString &szFolderPath)
intended to by called from your OnSelChanged() callback function. The CString object will contain
the path of that folder selected if FolderSelected() returns TRUE. If it returns FALSE, the
node selected isn't part of the filesystem and has no path.
PS: Use this function if you need to set the path in a corresponding combobox or editwindow.
void CTreeExampleDlg::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
CString SelPath;
if(m_TreeCtl->OnFolderSelected(pNMHDR,pResult,SelPath))
MessageBox(SelPath);
*pResult = 0;
}
comments: The above code displays the path of the Folder selected if it's in the filesystem.
9. You must allow CShellTree to release the memory allocated for the Shellobjects. in your
OnDeleteItem(), a callback to TVN_DELETEITEM, CShellTree provides a method
void OnDeleteShellItem(NMHDR* pNMHDR, LRESULT* pResult);
You must absolutely call this method or your project will leak memory
void CTreeExampleDlg::OnDeleteitem(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
m_TreeCtl->OnDeleteShellItem(pNMHDR,pResult);
*pResult = 0;
}
MISC NOTES:
===========
1. void CShellTree::TunnelTree(CString szFindPath) requires that you
implement the TVN_SELCHANGED message handler. TunnelTree will just
just not work if you do NOT implement it. Works only on folders under "MY COMPUTER"
This means local drives and mapped network drives. No network neighbourhood or whatever
2. void CShellTree::PopulateTree(int nSpecialFolder) will start the tree at
a special folder location. See ::ShBrowseForFolder() and ::ShGetSpecialFolderLocation().
CShellTree::TunnelTree() will not work if you use this method to initialize the tree.
HISTORY:
========
v1.02
- Fixed a skipped initialization of a variable that caused TunnelTree() to crash on WinNT
if the folder didn't have any subfolders
- Added TunnelTree(CString szFindPath) and PopulateTree(int SpecialFolder) methods
- Implemented a required call to OnDeleteShellItem(); TVN_DELETEITEM, that released the memory
allocated by that shell folder
========
BONUS: You can get the path of the Selected Node by calling GetSelectedFolderPath(). It will
return TRUE if the selected Folder is part of
没有合适的资源?快使用搜索试试~ 我知道了~
VC界面编程源码百例
共2776个文件
h:708个
cpp:616个
ico:237个
4星 · 超过85%的资源 需积分: 9 70 下载量 31 浏览量
2009-04-18
09:21:48
上传
评论
收藏 7.97MB RAR 举报
温馨提示
VC界面编程源码百例 包括按钮 树控件的常用的控件用法等等
资源推荐
资源详情
资源评论
收起资源包目录
VC界面编程源码百例 (2776个子文件)
Stealth.001 9KB
pushpindemo.001 9KB
TrayCalender.001 9KB
Strtmenu.001 7KB
ticktest.001 7KB
TemplateMFC.001 7KB
Traytest.001 7KB
ToolbarMenuDemoMDI.001 6KB
MvTest.001 5KB
MultiScreen.001 5KB
StatusBar.001 5KB
Wzd.001 5KB
fontsTest.001 5KB
datapkproj.001 5KB
Xx.001 5KB
TaskBar.001 5KB
Wzd.001 5KB
Example.001 5KB
Example.001 5KB
hovbutt.001 5KB
OSDetect.001 5KB
FontTest.001 4KB
LookMaSDI.001 4KB
MRUComboTest.001 4KB
PropertySheetWithLogo.001 4KB
colorBtnSample.001 4KB
SysImageList.001 4KB
RegistryDemo.001 4KB
TriangleButtonDemo.001 4KB
IPTest.001 4KB
CBCPTest.001 4KB
seek.001 4KB
Pizza.001 4KB
Q.001 4KB
RangeEdit.001 4KB
FourSeasons.001 3KB
baldie.ani 3KB
test.aps 199KB
win32.aps 183KB
avibtntest.aps 178KB
ExToolBar.aps 127KB
WavTipSample.aps 108KB
TrayCalender.aps 76KB
Transparent.aps 73KB
CButtonST_demo.aps 64KB
Demo_DevStudio.aps 58KB
HDDemo.aps 57KB
MvTest.aps 54KB
CtrlTest.aps 52KB
MSDIDAO.APS 51KB
TREELIST.APS 50KB
StatusBar.aps 50KB
HtmlViews.aps 47KB
MDIWindList.aps 47KB
Xx.aps 47KB
datapkproj.aps 46KB
ToolbarMenuDemoMDI.aps 46KB
DemoToolTip.aps 45KB
Avidemo.aps 44KB
BmpButton.aps 43KB
TextInStatus.aps 43KB
ex11.aps 43KB
OSDetect.aps 42KB
TemplateMFC.aps 39KB
Eureka.aps 39KB
GridCtrlDemo.aps 38KB
MSDITest.aps 37KB
HardwareInfo.aps 37KB
TaskBar.aps 36KB
Example.aps 36KB
LookMaSDI.aps 35KB
Q.APS 35KB
fontsTest.aps 35KB
TriangleButtonDemo.aps 35KB
HexEdit.aps 35KB
QuatRotDemo.aps 35KB
FontTest.aps 35KB
Dialog.aps 35KB
TreeExample.aps 34KB
CBCPTest.aps 34KB
Demo.aps 34KB
Traytest.aps 34KB
MultiScreen.aps 34KB
RndBtnDemo.aps 34KB
ComboExDemo.aps 34KB
RangeEdit.aps 33KB
FScript.aps 32KB
DemoTBarC.aps 32KB
Strtmenu.aps 32KB
MultiWindow.aps 29KB
hovbutt.aps 27KB
digitalclock.aps 26KB
MRUComboTest.aps 22KB
ExpandDialog.aps 21KB
PropertySheetWithLogo.aps 21KB
IPTest.aps 20KB
ProgressBarDemo.aps 20KB
ok2.avi 158KB
ie4.avi 12KB
filecopy.avi 9KB
共 2776 条
- 1
- 2
- 3
- 4
- 5
- 6
- 28
资源评论
- IT_NEU_20092012-09-19学习了,原来界面还有这么多东西
- fanhongjun20042014-04-03很好的案例,代码不错,希望多有点
jf2820022003
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功