ReactOS  0.4.14-dev-115-g4576127
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 
78 int 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 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
file system path of special folder
Definition: fci.c:115
HRESULT hr
Definition: shlfolder.c:183
const GLint * attribs
Definition: glext.h:10538
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
IShellFolder smart pointer.
Definition: shellclasses.h:593
#define CSIDL_PROGRAM_FILES
Definition: shlobj.h:2040
static WCHAR String[]
Definition: stringtable.c:55
#define BIF_EDITBOX
Definition: shlobj.h:1139
static const char hex[16]
Definition: profile.c:123
Exception with context information.
Definition: shellclasses.h:113
#define cout
Definition: iostream.cpp:38
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
wrapper class for enumerating shell namespace objects
#define e
Definition: ke_i.h:82
#define S_FALSE
Definition: winerror.h:2357
int main()
Definition: shelltests.cpp:78
#define BIF_NEWDIALOGSTYLE
Definition: shlobj.h:1141
_STLP_DECLSPEC _Stl_aligned_buffer< ostream > cerr
Definition: iostream.cpp:102
LONG HRESULT
Definition: typedefs.h:77
const GLuint * programs
Definition: glext.h:6724
static void dump_shell_namespace(ShellFolder &folder)
Definition: shelltests.cpp:37
#define MessageBox
Definition: winuser.h:5723
#define CSIDL_STARTUP
Definition: shlobj.h:2010
ShellFolder & GetDesktopFolder()
Browse dialog operating on shell namespace.
Definition: shellclasses.h:947
#define S_OK
Definition: intsafe.h:59
#define TEXT(s)
Definition: k32.h:26
#define BIF_RETURNONLYFSDIRS
Definition: shlobj.h:1135
#define MB_OK
Definition: winuser.h:784
Definition: name.c:36
#define BIF_VALIDATE
Definition: shlobj.h:1140
unsigned int ULONG
Definition: retypes.h:1
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
wrapper class for item ID lists
Definition: shellclasses.h:651
#define SUCCEEDED(hr)
Definition: intsafe.h:57
COM Initialisation.
Definition: shellclasses.h:178