aie, le beau truc bien chiant.
Je cherche a choper les icônes 48*48 de n'importe quel fichier. mais ça à l'air d'être un peu trop chiadé pour moi. Si quelqu'un peut me filer un coup de main.
j'ai trouvé ce code en exemple, c'est pas du PB
Code : Tout sélectionner
#include <shlobj.h>
#include <shlguid.h>
#include <shellapi.h>
#include <commctrl.h>
#include <commoncontrols.h>
// Get the icon index using SHGetFileInfo
SHFILEINFOW sfi = {0};
SHGetFileInfo(filePath, -1, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX);
// Retrieve the system image list.
// To get the 48x48 icons, use SHIL_EXTRALARGE
// To get the 256x256 icons (Vista only), use SHIL_JUMBO
HIMAGELIST* imageList;
HRESULT hResult = SHGetImageList(SHIL_EXTRALARGE, IID_IImageList, (void**)&imageList);
if (hResult == S_OK) {
// Get the icon we need from the list. Note that the HIMAGELIST we retrieved
// earlier needs to be casted to the IImageList interface before use.
HICON hIcon;
hResult = ((IImageList*)imageList)->GetIcon(sfi.iIcon, ILD_TRANSPARENT, &hIcon);
if (hResult == S_OK) {
// Do something with the icon here.
// For example, in wxWidgets:
wxIcon* icon = new wxIcon();
icon->SetHICON((WXHICON)hIcon);
icon->SetSize(48, 48);
}
}
Code : Tout sélectionner
; Auteur : Le Soldat Inconnu
; Version de PB : 4
;
; Explication du programme :
; Récupérer une icône de la taille 16*16, 32*32, 48*48
#SHIL_EXTRALARGE = $2
; Création de la fenêtre et de la GadgetList
If OpenWindow(0, 0, 0, 300, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget) = 0
End
EndIf
IconPath.s = "c:\"
SHGetFileInfo_(IconPath, -1, @InfosFile.SHFILEINFO, SizeOf(SHFILEINFO), #SHGFI_SYSICONINDEX)
dll_Shell32 = OpenLibrary(#PB_Any, "Shell32.dll")
If dll_Shell32
hResult = CallFunction(dll_Shell32, "SHGetImageList", #SHIL_EXTRALARGE, IID_IImageList, @ImageList)
If hResult = 0
Debug "ok"
EndIf
EndIf
ImageGadget(0, 0, 0, 48, 48, Icone)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
If Icone
DestroyIcon_(Icone)
EndIf
pour info, récupérer du 16*16 ou 32*32 est bien plus simple. Voilà ce que j'utilise
Code : Tout sélectionner
ProcedureDLL.l GetSmallIconFile(IconPath.s) ; Extraire l'icône 16*16 d'un fichier
; Cette procedure permet d'extraire l'ID de l'icône 16*16 associé au type de fichier ou au dossier dont l'adresse est IconPath
Extension.s = LCase(GetExtensionPart(IconPath))
If Extension = "ico" Or Extension = "exe"
ExtractIconEx_(IconPath, IconIndex, 0, @SmallIcon, 1)
ProcedureReturn SmallIcon
Else
SHGetFileInfo_(IconPath, 0, @InfosFile.SHFILEINFO, SizeOf(SHFILEINFO), #SHGFI_ICON | #SHGFI_SMALLICON)
ProcedureReturn InfosFile\hIcon
EndIf
EndProcedure
ProcedureDLL.l GetLargeIconFile(IconPath.s) ; Extraire l'icône 32*32 d'un fichier
; Cette procedure permet d'extraire l'ID de l'icône 32*32 associé au type de fichier ou au dossier dont l'adresse est IconPath
Extension.s = LCase(GetExtensionPart(IconPath))
If Extension = "ico" Or Extension = "exe"
ExtractIconEx_(IconPath, IconIndex, @LargeIcon, 0, 1)
ProcedureReturn LargeIcon
Else
SHGetFileInfo_(IconPath, 0, @InfosFile.SHFILEINFO, SizeOf(SHFILEINFO), #SHGFI_ICON | #SHGFI_LARGEICON)
ProcedureReturn InfosFile\hIcon
EndIf
EndProcedure