ReactOS 0.4.16-dev-250-g3ecd236
shelltests.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2003 Martin Fuchs
3 *
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.
8 *
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.
13 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19
20 //
21 // shelltests.cpp
22 //
23 // Examples for usage of shellclasses.cpp, shellclasses.h
24 //
25 // Martin Fuchs, 20.07.2003
26 //
27
28
29//#define WIN32_LEAN_AND_MEAN
30//#define WIN32_EXTRA_LEAN
31//#include <windows.h>
32
33#include "utility.h" // for String
34#include "shellclasses.h"
35
36
38{
39 ShellItemEnumerator enumerator(folder, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE);
40
41 LPITEMIDLIST pidl;
42 HRESULT hr = S_OK;
43
44 do {
45 ULONG cnt = 0;
46
47 HRESULT hr = enumerator->Next(1, &pidl, &cnt);
48
49 if (!SUCCEEDED(hr))
50 break;
51
52 if (hr == S_FALSE) // no more entries?
53 break;
54
55 if (pidl) {
56 ULONG attribs = -1;
57
58 HRESULT hr = folder->GetAttributesOf(1, (LPCITEMIDLIST*)&pidl, &attribs);
59
60 if (SUCCEEDED(hr)) {
61 if (attribs == -1)
62 attribs = 0;
63
64 const String& name = folder.get_name(pidl);
65
66 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
67 cout << "folder: ";
68 else
69 cout << "file: ";
70
71 cout << "\"" << name << "\"\n attribs=" << hex << attribs << endl;
72 }
73 }
74 } while(SUCCEEDED(hr));
75}
76
77
78int main()
79{
80 // initialize COM
81 ComInit usingCOM;
82
83
84 HWND hwnd = 0;
85
86
87 try {
88
89 // example for retrieval of special folder paths
90
93
94 cout << "program files path = " << (LPCTSTR)programs << endl;
95 cout << "autostart folder path = " << (LPCTSTR)autostart << endl;
96
97 cout << endl;
98
99
100 // example for enumerating shell namespace objects
101
102 cout << "Desktop:\n";
104 cout << endl;
105
106 cout << "C:\\\n";
107 dump_shell_namespace(ShellPath("C:\\").get_folder());
108 cout << endl;
109
110
111 // example for calling a browser dialog for the whole desktop
112
113 FolderBrowser desktop_browser(hwnd,
115 TEXT("Please select the path:"));
116
117 if (desktop_browser.IsOK())
118 MessageBox(hwnd, desktop_browser, TEXT("Your selected path"), MB_OK);
119
120
121 // example for calling a rooted browser dialog
122
123 ShellPath browseRoot("C:\\");
124 FolderBrowser rooted_browser(hwnd,
126 TEXT("Please select the path:"),
127 browseRoot);
128
129 if (rooted_browser.IsOK())
130 MessageBox(hwnd, rooted_browser, TEXT("Your selected path"), MB_OK);
131
132 } catch(COMException& e) {
133
134 //HandleException(e, hwnd);
135 cerr << e.ErrorMessage() << endl;
136
137 }
138
139 return 0;
140}
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
const GLuint * programs
Definition: glext.h:6724
const GLint * attribs
Definition: glext.h:10538
int hex(char ch)
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define cout
Definition: iostream.cpp:38
#define cerr
Definition: iostream.cpp:39
#define TEXT(s)
Definition: k32.h:26
#define e
Definition: ke_i.h:82
ShellFolder & GetDesktopFolder()
static void dump_shell_namespace(ShellFolder &folder)
Definition: shelltests.cpp:37
int main()
Definition: shelltests.cpp:78
HRESULT hr
Definition: shlfolder.c:183
#define BIF_VALIDATE
Definition: shlobj.h:1222
#define CSIDL_PROGRAM_FILES
Definition: shlobj.h:2210
#define BIF_RETURNONLYFSDIRS
Definition: shlobj.h:1217
#define CSIDL_STARTUP
Definition: shlobj.h:2180
#define BIF_NEWDIALOGSTYLE
Definition: shlobj.h:1223
#define BIF_EDITBOX
Definition: shlobj.h:1221
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
Exception with context information.
Definition: shellclasses.h:114
COM Initialisation.
Definition: shellclasses.h:179
Browse dialog operating on shell namespace.
Definition: shellclasses.h:948
IShellFolder smart pointer.
Definition: shellclasses.h:594
wrapper class for enumerating shell namespace objects
wrapper class for item ID lists
Definition: shellclasses.h:652
file system path of special folder
Definition: fci.c:116
Definition: name.c:39
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define S_FALSE
Definition: winerror.h:2357
#define MB_OK
Definition: winuser.h:793
#define MessageBox
Definition: winuser.h:5834
const CHAR * LPCTSTR
Definition: xmlstorage.h:193