00001 /* 00002 * Copyright 2003 Martin Fuchs 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 00020 // 00021 // shelltests.cpp 00022 // 00023 // Examples for usage of shellclasses.cpp, shellclasses.h 00024 // 00025 // Martin Fuchs, 20.07.2003 00026 // 00027 00028 00029 //#define WIN32_LEAN_AND_MEAN 00030 //#define WIN32_EXTRA_LEAN 00031 //#include <windows.h> 00032 00033 #include "utility.h" // for String 00034 #include "shellclasses.h" 00035 00036 00037 static void dump_shell_namespace(ShellFolder& folder) 00038 { 00039 ShellItemEnumerator enumerator(folder, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE); 00040 00041 LPITEMIDLIST pidl; 00042 HRESULT hr = S_OK; 00043 00044 do { 00045 ULONG cnt = 0; 00046 00047 HRESULT hr = enumerator->Next(1, &pidl, &cnt); 00048 00049 if (!SUCCEEDED(hr)) 00050 break; 00051 00052 if (hr == S_FALSE) // no more entries? 00053 break; 00054 00055 if (pidl) { 00056 ULONG attribs = -1; 00057 00058 HRESULT hr = folder->GetAttributesOf(1, (LPCITEMIDLIST*)&pidl, &attribs); 00059 00060 if (SUCCEEDED(hr)) { 00061 if (attribs == -1) 00062 attribs = 0; 00063 00064 const String& name = folder.get_name(pidl); 00065 00066 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER)) 00067 cout << "folder: "; 00068 else 00069 cout << "file: "; 00070 00071 cout << "\"" << name << "\"\n attribs=" << hex << attribs << endl; 00072 } 00073 } 00074 } while(SUCCEEDED(hr)); 00075 } 00076 00077 00078 int main() 00079 { 00080 // initialize COM 00081 ComInit usingCOM; 00082 00083 00084 HWND hwnd = 0; 00085 00086 00087 try { 00088 00089 // example for retrieval of special folder paths 00090 00091 SpecialFolderFSPath programs(CSIDL_PROGRAM_FILES, hwnd); 00092 SpecialFolderFSPath autostart(CSIDL_STARTUP, hwnd); 00093 00094 cout << "program files path = " << (LPCTSTR)programs << endl; 00095 cout << "autostart folder path = " << (LPCTSTR)autostart << endl; 00096 00097 cout << endl; 00098 00099 00100 // example for enumerating shell namespace objects 00101 00102 cout << "Desktop:\n"; 00103 dump_shell_namespace(GetDesktopFolder()); 00104 cout << endl; 00105 00106 cout << "C:\\\n"; 00107 dump_shell_namespace(ShellPath("C:\\").get_folder()); 00108 cout << endl; 00109 00110 00111 // example for calling a browser dialog for the whole desktop 00112 00113 FolderBrowser desktop_browser(hwnd, 00114 BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_NEWDIALOGSTYLE, 00115 TEXT("Please select the path:")); 00116 00117 if (desktop_browser.IsOK()) 00118 MessageBox(hwnd, desktop_browser, TEXT("Your selected path"), MB_OK); 00119 00120 00121 // example for calling a rooted browser dialog 00122 00123 ShellPath browseRoot("C:\\"); 00124 FolderBrowser rooted_browser(hwnd, 00125 BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_VALIDATE, 00126 TEXT("Please select the path:"), 00127 browseRoot); 00128 00129 if (rooted_browser.IsOK()) 00130 MessageBox(hwnd, rooted_browser, TEXT("Your selected path"), MB_OK); 00131 00132 } catch(COMException& e) { 00133 00134 //HandleException(e, hwnd); 00135 cerr << e.ErrorMessage() << endl; 00136 00137 } 00138 00139 return 0; 00140 }
ROS Explorer Source Code Documentation
generated on 02.01.2013 by ![]() |