Something went wrong. Try again.
Reactos
Something went wrong. Try again.
3.3 kB · 140 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141/* * Copyright 2003 Martin Fuchs * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
// // shelltests.cpp // // Examples for usage of shellclasses.cpp, shellclasses.h // // Martin Fuchs, 20.07.2003 //
//#define WIN32_LEAN_AND_MEAN//#define WIN32_EXTRA_LEAN//#include <windows.h>
#include "utility.h" // for String#include "shellclasses.h"
static void dump_shell_namespace(ShellFolder& folder){ ShellItemEnumerator enumerator(folder, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE);
LPITEMIDLIST pidl; HRESULT hr = S_OK;
do { ULONG cnt = 0;
HRESULT hr = enumerator->Next(1, &pidl, &cnt);
if (!SUCCEEDED(hr)) break;
if (hr == S_FALSE) // no more entries? break;
if (pidl) { ULONG attribs = -1;
HRESULT hr = folder->GetAttributesOf(1, (LPCITEMIDLIST*)&pidl, &attribs);
if (SUCCEEDED(hr)) { if (attribs == -1) attribs = 0;
const String& name = folder.get_name(pidl);
if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER)) cout << "folder: "; else cout << "file: ";
cout << "\"" << name << "\"\n attribs=" << hex << attribs << endl; } } } while(SUCCEEDED(hr));}
int main(){ // initialize COM ComInit usingCOM;
HWND hwnd = 0;
try {
// example for retrieval of special folder paths
SpecialFolderFSPath programs(CSIDL_PROGRAM_FILES, hwnd); SpecialFolderFSPath autostart(CSIDL_STARTUP, hwnd);
cout << "program files path = " << (LPCTSTR)programs << endl; cout << "autostart folder path = " << (LPCTSTR)autostart << endl;
cout << endl;
// example for enumerating shell namespace objects
cout << "Desktop:\n"; dump_shell_namespace(GetDesktopFolder()); cout << endl;
cout << "C:\\\n"; dump_shell_namespace(ShellPath("C:\\").get_folder()); cout << endl;
// example for calling a browser dialog for the whole desktop
FolderBrowser desktop_browser(hwnd, BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_NEWDIALOGSTYLE, TEXT("Please select the path:"));
if (desktop_browser.IsOK()) MessageBox(hwnd, desktop_browser, TEXT("Your selected path"), MB_OK);
// example for calling a rooted browser dialog
ShellPath browseRoot("C:\\"); FolderBrowser rooted_browser(hwnd, BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_VALIDATE, TEXT("Please select the path:"), browseRoot);
if (rooted_browser.IsOK()) MessageBox(hwnd, rooted_browser, TEXT("Your selected path"), MB_OK);
} catch(COMException& e) {
//HandleException(e, hwnd); cerr << e.ErrorMessage() << endl;
}
return 0;}