+#ifdef SHGSI_ICON
+ #define wxHAS_SHGetStockIconInfo
+#endif
+
+namespace
+{
+
+#ifdef wxHAS_SHGetStockIconInfo
+
+SHSTOCKICONID MSWGetStockIconIdForArtProviderId(const wxArtID& art_id)
+{
+ // try to find an equivalent MSW stock icon id for wxArtID
+ if ( art_id == wxART_ERROR) return SIID_ERROR;
+ else if ( art_id == wxART_QUESTION ) return SIID_HELP;
+ else if ( art_id == wxART_WARNING ) return SIID_WARNING;
+ else if ( art_id == wxART_INFORMATION ) return SIID_INFO;
+ else if ( art_id == wxART_HELP ) return SIID_HELP;
+ else if ( art_id == wxART_FOLDER ) return SIID_FOLDER;
+ else if ( art_id == wxART_FOLDER_OPEN ) return SIID_FOLDEROPEN;
+ else if ( art_id == wxART_DELETE ) return SIID_DELETE;
+ else if ( art_id == wxART_FIND ) return SIID_FIND;
+ else if ( art_id == wxART_HARDDISK ) return SIID_DRIVEFIXED;
+ else if ( art_id == wxART_FLOPPY ) return SIID_DRIVE35;
+ else if ( art_id == wxART_CDROM ) return SIID_DRIVECD;
+ else if ( art_id == wxART_REMOVABLE ) return SIID_DRIVEREMOVE;
+
+ return SIID_INVALID;
+};
+
+
+// try to load SHGetStockIconInfo dynamically, so this code runs
+// even on pre-Vista Windows versions
+HRESULT
+MSW_SHGetStockIconInfo(SHSTOCKICONID siid,
+ UINT uFlags,
+ SHSTOCKICONINFO *psii)
+{
+ typedef HRESULT (WINAPI *PSHGETSTOCKICONINFO)(SHSTOCKICONID, UINT, SHSTOCKICONINFO *);
+ static PSHGETSTOCKICONINFO pSHGetStockIconInfo = (PSHGETSTOCKICONINFO)-1;
+
+ if ( pSHGetStockIconInfo == (PSHGETSTOCKICONINFO)-1 )
+ {
+ wxDynamicLibrary shell32(wxT("shell32.dll"));
+
+ pSHGetStockIconInfo = (PSHGETSTOCKICONINFO)shell32.RawGetSymbol( wxT("SHGetStockIconInfo") );
+ }
+
+ if ( !pSHGetStockIconInfo )
+ return E_FAIL;
+
+ return pSHGetStockIconInfo(siid, uFlags, psii);
+}
+
+#endif // #ifdef wxHAS_SHGetStockIconInfo
+
+wxBitmap
+MSWGetBitmapForPath(const wxString& path, const wxSize& size, DWORD uFlags = 0)
+{
+ SHFILEINFO fi;
+ wxZeroMemory(fi);
+
+ uFlags |= SHGFI_USEFILEATTRIBUTES | SHGFI_ICON;
+ if ( size != wxDefaultSize )
+ {
+ if ( size.x <= 16 )
+ uFlags |= SHGFI_SMALLICON;
+ else if ( size.x >= 64 )
+ uFlags |= SHGFI_LARGEICON;
+ }
+
+ if ( !SHGetFileInfo(path.t_str(), FILE_ATTRIBUTE_DIRECTORY,
+ &fi, sizeof(SHFILEINFO), uFlags) )
+ return wxNullBitmap;
+
+ wxIcon icon;
+ icon.CreateFromHICON((WXHICON)fi.hIcon);
+
+ wxBitmap bitmap(icon);
+ ::DestroyIcon(fi.hIcon);
+
+ return bitmap;
+}
+
+#if wxUSE_FSVOLUME
+
+wxBitmap
+GetDriveBitmapForVolumeType(const wxFSVolumeKind& volKind, const wxSize& size)
+{
+ // get all volumes and try to find one with a matching type
+ wxArrayString volumes = wxFSVolume::GetVolumes();
+ for ( size_t i = 0; i < volumes.Count(); i++ )
+ {
+ wxFSVolume vol( volumes[i] );
+ if ( vol.GetKind() == volKind )
+ {
+ return MSWGetBitmapForPath(volumes[i], size);
+ }
+ }
+
+ return wxNullBitmap;
+}
+
+#endif // wxUSE_FSVOLUME
+
+} // anonymous namespace