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
Visual C++高级界面制作(六)
需积分: 0 39 浏览量
更新于2008-12-23
收藏 230KB RAR 举报
在本篇中,我们将深入探讨"Visual C++高级界面制作(六)"这一主题,它主要涉及使用Microsoft的Visual C++开发环境来构建复杂、功能丰富的用户界面。Visual C++作为一个强大的开发工具,允许程序员利用MFC(Microsoft Foundation Classes)库来创建Windows应用程序,其高级界面制作通常涉及到自定义控件、动态布局、多线程以及与其他系统组件的深度集成。
自定义控件是提升界面独特性和功能性的关键。在Visual C++中,可以通过继承MFC的CWnd类或已有的控件类(如CButton、CEdit等)来创建自己的控件。这通常涉及到重写消息映射函数,处理WM_PAINT消息以绘制控件,以及实现其他所需的行为。此外,利用GDI(Graphics Device Interface)和GDI+库可以实现复杂的图形绘制,为用户界面增添动态效果。
动态布局管理是另一个重要话题。在设计用户界面时,我们往往希望界面元素能够根据窗口大小的变化自动调整位置和大小。Visual C++提供了CLayoutView类和相关的布局策略,使得开发者能轻松实现网格布局、流式布局等常见布局模式。通过使用这些布局机制,可以确保应用在不同分辨率和屏幕尺寸下的表现一致。
再者,多线程技术在构建高级界面时也起着至关重要的作用。多线程可以提高应用的响应性,避免UI线程因执行耗时操作而阻塞。在Visual C++中,可以使用CWinThread类创建新的线程,并使用适当的同步机制(如CSemaphore、CCriticalSection等)来确保数据访问的安全性。
除了上述技术,高级界面制作还包括与数据库、网络、硬件设备等的交互。例如,使用ODBC或ADO(ActiveX Data Objects)来连接和操作数据库,或者利用Winsock库进行网络通信。同时,Visual C++还支持COM(Component Object Model)和ATL(Active Template Library)来创建COM组件,这使得与其他应用程序和服务的集成变得简单。
此外,国际化和本地化也是高级界面设计要考虑的因素。Visual C++提供了资源文件和MFC的国际化支持,允许开发者创建支持多种语言的界面。这包括设置多语言字符串、图标和日期/时间格式等。
我们不能忽视调试和性能优化的重要性。Visual C++的调试器提供了强大的工具,如断点、变量监视、调用堆栈查看等,帮助开发者查找并修复错误。同时,使用性能分析器可以找出程序的瓶颈,进行代码优化,提高运行效率。
在"char06"这个文件中,可能包含了第六部分的源代码示例,演示了上述概念的应用。通过学习和理解这些代码,读者将能够更好地掌握Visual C++高级界面制作的技术,并将其应用于实际项目中,创造出更出色、更高效的用户界面。
davewxf
- 粉丝: 2
- 资源: 27
最新资源
- 博思智联-三联集团-新乡连锁店培训流程说明.doc
- 博思智联-三联集团-职位评估培训.ppt
- 博思智联-三联集团-新乡培训流程说明.doc
- Delphi编程-Oracle-控件-delphi连接Oracle数据库控件
- mysql安装配置教程.txt
- 泛华-中国青年报项目—岗 位 描 述 书培训模搬.doc
- 和君创业—上海西域酒业项目培训—培训计划2.doc
- 和君创业—上海西域酒业项目培训—培训小结(提要)学员使用.doc
- 和君创业—上海西域酒业项目培训—业务员培训资料目录.doc
- 基于antlr4 解析器,支持spark sql, tidb sql, flink sql, Sparkflink jar 运行命令解析器详细文档+全部资料.zip
- 毕业设计:基于MQTT的物联网设备接入平台、使用Flink流处理框架详细文档+全部资料.zip
- 基于 SSM 框架,Flink 流,MySQL 数据库、BS 架构的小说网站详细文档+全部资料.zip
- 基于docker的实时监控系统,详细文档+全部资料.zip
- 基于Bilibili公开的数据,通过Flink实时分析计算,做成需要的动态图表详细文档+全部资料.zip
- IMG_20241218_182829.jpg
- 华彩--三鼎控股—华鼎锦纶子集团培训管理办法--外派培训9.27.doc