Module pour choisir une icône (Windows)
Publié : dim. 16/juil./2017 22:35
J'ai essayé de faire ce module pour mes besoins. Quelques fonctions similaires existaient bien, mais aucune ne retourne le chemin du fichier dans lequel on sélectionne l'icône.
Je ne suis pas expert, mais ça semble fonctionner comme il faut, aussi bien compilé en Unicode ou non.
Je ne suis pas expert, mais ça semble fonctionner comme il faut, aussi bien compilé en Unicode ou non.
Code : Tout sélectionner
DeclareModule IconDlg
Declare.b Pick(iconfile.s = "", iconindex = 0, hWnd.i = 0)
Global.s icon
Global.i index
EndDeclareModule
Module IconDlg
Prototype.i PickIconDlg(hwnd.i, *pszIconPath, cchIconPath, *piIconIndex)
Procedure.b Pick(iconfile.s = "", iconindex = 0, hWnd.i = 0)
Protected.String library
Protected.PickIconDlg PickIconDlg
Protected.i idLib, result, szbuffer
Protected *buffer
library\s = iconfile
index = iconindex
idLib = OpenLibrary(#PB_Any, "Shell32.dll")
If idLib
PickIconDlg = GetFunction(idLib, "PickIconDlg")
If library\s = ""
library\s = Space(#MAX_PATH)
GetWindowsDirectory_(library\s, #MAX_PATH)
library\s + "\system32\shell32.dll"
index = 0
EndIf
szbuffer = #MAX_PATH + 1
CompilerIf Not #PB_Compiler_Unicode: szbuffer * 2: CompilerEndIf
*buffer = AllocateMemory(szbuffer)
PokeS(*buffer, library\s, -1, #PB_Unicode)
If PickIconDlg(0, *buffer, szbuffer, @index)
icon = PeekS(*buffer, -1, #PB_Unicode)
result = #True
Else
result = #False
EndIf
FreeMemory(*buffer)
CloseLibrary(idLib)
EndIf
ProcedureReturn result
EndProcedure
EndModule
; IconDlg::Pick(iconfile.s, iconindex.i, hWnd.i)
; iconfile -> (Optionel - Shell32.dll par défaut) La librairie, l'exécutable ou l'icône à ouvrir dans le dialogue
; iconindex -> (Optionel - 0 par défaut) L'index de l'icône dans le fichier. Par défaut: 0
; hWnd -> (Optionel- 0 par défaut) Le handle de la fenêtre de votre application si nécessaire. Par défaut: 0
; Retour -> #True si ok sinon #False
;
; IconDlg::icon
; Retour: -> Le fichier dans lequel l'icône a été sélectionnée.
;
; IconDlg::index
; Retour: -> L'index de l'icône dans le fichier dans lequel elle a été sélectionnée.
CompilerIf #PB_Compiler_IsMainFile
If IconDlg::Pick("C:\Windows\System32\imageres.dll", 15)
Debug "Fichier contenant l'icône: " + IconDlg::icon
Debug "Index de l'icône: " + IconDlg::index
EndIf
CompilerEndIf