2 * Copyright 2003 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 // Examples for usage of shellclasses.cpp, shellclasses.h
25 // Martin Fuchs, 20.07.2003
29 //#define WIN32_LEAN_AND_MEAN
30 //#define WIN32_EXTRA_LEAN
31 //#include <windows.h>
33 #include "utility.h" // for String
34 #include "shellclasses.h"
37 static void dump_shell_namespace(ShellFolder
& folder
)
39 ShellItemEnumerator
enumerator(folder
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
);
47 HRESULT hr
= enumerator
->Next(1, &pidl
, &cnt
);
52 if (hr
== S_FALSE
) // no more entries?
58 HRESULT hr
= folder
->GetAttributesOf(1, (LPCITEMIDLIST
*)&pidl
, &attribs
);
64 const String
& name
= folder
.get_name(pidl
);
66 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
71 cout
<< "\"" << name
<< "\"\n attribs=" << hex
<< attribs
<< endl
;
74 } while(SUCCEEDED(hr
));
89 // example for retrieval of special folder paths
91 SpecialFolderFSPath
programs(CSIDL_PROGRAM_FILES
, hwnd
);
92 SpecialFolderFSPath
autostart(CSIDL_STARTUP
, hwnd
);
94 cout
<< "program files path = " << (LPCTSTR
)programs
<< endl
;
95 cout
<< "autostart folder path = " << (LPCTSTR
)autostart
<< endl
;
100 // example for enumerating shell namespace objects
102 cout
<< "Desktop:\n";
103 dump_shell_namespace(GetDesktopFolder());
107 dump_shell_namespace(ShellPath("C:\\").get_folder());
111 // example for calling a browser dialog for the whole desktop
113 FolderBrowser
desktop_browser(hwnd
,
114 BIF_RETURNONLYFSDIRS
|BIF_EDITBOX
|BIF_NEWDIALOGSTYLE
,
115 TEXT("Please select the path:"));
117 if (desktop_browser
.IsOK())
118 MessageBox(hwnd
, desktop_browser
, TEXT("Your selected path"), MB_OK
);
121 // example for calling a rooted browser dialog
123 ShellPath
browseRoot("C:\\");
124 FolderBrowser
rooted_browser(hwnd
,
125 BIF_RETURNONLYFSDIRS
|BIF_EDITBOX
|BIF_VALIDATE
,
126 TEXT("Please select the path:"),
129 if (rooted_browser
.IsOK())
130 MessageBox(hwnd
, rooted_browser
, TEXT("Your selected path"), MB_OK
);
132 } catch(COMException
& e
) {
134 //HandleException(e, hwnd);
135 cerr
<< e
.ErrorMessage() << endl
;