GME
13
|
00001 00002 #define NTDDI_VERSION 0x06000000 00003 #define _WIN32_WINNT 0x0600 00004 00005 #include <afxwin.h> 00006 #include <ShObjIdl.h> 00007 #include <atlcomcli.h> 00008 #include <atlstr.h> 00009 00010 HRESULT VistaBrowseDirectory(CString& directory) 00011 { 00012 CComPtr<IFileDialog> pfd; 00013 HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, 00014 NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd)); 00015 if (FAILED(hr)) 00016 return hr; 00017 00018 DWORD dwFlags; 00019 hr = pfd->GetOptions(&dwFlags); 00020 if (FAILED(hr)) 00021 return hr; 00022 hr = pfd->SetOptions(dwFlags | FOS_FORCEFILESYSTEM | FOS_PICKFOLDERS); 00023 if (FAILED(hr)) 00024 return hr; 00025 hr = pfd->Show(NULL); 00026 if (FAILED(hr)) 00027 return hr; // may be HRESULT_FROM_WIN32(ERROR_CANCELLED) 00028 00029 CComPtr<IShellItem> psiResult; 00030 hr = pfd->GetResult(&psiResult); 00031 if (FAILED(hr)) 00032 return hr; 00033 PWSTR pszFilePath = NULL; 00034 hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); 00035 if (FAILED(hr)) 00036 return hr; 00037 directory = pszFilePath; 00038 CoTaskMemFree(pszFilePath); 00039 00040 return hr; 00041 }