[R] Afficher icônes en grand

Aide et conseils concernant AutoIt et ses outils.
Règles du forum
.
Répondre
micam
Niveau 1
Niveau 1
Messages : 2
Enregistré le : dim. 29 janv. 2017 12:01
Status : Hors ligne

[R] Afficher icônes en grand

#1

Message par micam »

Bonjour,
J'aimerai afficher dans une listbox ou une listview (je ne sais, pas ce qui est le mieux), des icônes extraites d'un exe, ou d'un raccourcis déjà existant (ça je ne sais pas le faire).
J'aimerai faire un launcher qui me permettra de classer mes icônes par catégories (genre "Fsl Launcher" qui ne me convient pas tout à fait).
Quand j'extrait d'un exe et que je change la taille en 128 x 128 le résultat n'est pas bon.

Launcher icônes agrandies en 128 x128
Launcher icônes agrandies en 128 x128
J'aimerai comme dans l'explorateur windows afficher en :

icônes moyennes
Launcher icônes moyennes
Launcher icônes moyennes
ou grandes icônes.
Launcher grandes icônes
Launcher grandes icônes
Merci de votre aide.

Code exemple :
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

Example()
;icone

Func Example()

Global $Form1 = GUICreate("Launcher", 592, 250, 192, 124)
Global $Tab1 = GUICtrlCreateTab(8, 8, 577, 225)
Global $Audio = GUICtrlCreateTabItem("Audio")
Global $Internet = GUICtrlCreateTabItem("Vidéos")
GUICtrlSetState(-1,$GUI_SHOW)
GUICtrlCreateTabItem("")
;Extrait les icones
GUICtrlCreateIcon("C:\Program Files\OpenShot Video Editor\blender\blender.exe", -1, 10, 40, 128, 128)
GUICtrlCreateIcon("C:\Program Files\ShareX\ShareX.exe", -1, 140, 40, 128, 128)
GUICtrlCreateIcon("D:\Downloads\captvty-2.6.2\Captvty.exe", -1, 270, 40, 128, 128)
    GUISetState(@SW_SHOW)

    ; Boucle jusqu'à ce que l'utilisateur quitte.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    GUIDelete()
EndFunc   ;==>Example
Modifié en dernier par micam le mar. 09 janv. 2018 09:21, modifié 1 fois.
Avatar du membre
walkson
Modérateur
Modérateur
Messages : 1020
Enregistré le : ven. 12 août 2011 19:49
Localisation : Hurepoix
Status : Hors ligne

Re: Afficher icônes en grand

#2

Message par walkson »

Bonjour,
Quelque chose comme çà ?
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
   Global $idListview, $hImage
   Local $sWow64 = ""
   If @AutoItX64 Then $sWow64 = "\Wow6432Node"
   Local $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\Advanced\Images"

   Global $hForm = GUICreate("ImageList AddBitmap", 400, 600)
   $idListview = GUICtrlCreateListView("", 2, 2, 394, 568, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
   _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
   GUISetState(@SW_SHOW)

   ; Load images
   $hImage = _GUIImageList_Create(128, 128,5)
   _GUIImageList_AddBitmap($hImage, $sPath & "\Red.bmp")
   _GUIImageList_AddBitmap($hImage, $sPath & "\Green.bmp")
   _GUIImageList_AddBitmap($hImage, $sPath & "\Blue.bmp")
   _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110,True)
   _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131,True)
   _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165,True)
   _GUIImageList_AddIcon($hImage, @ProgramFilesDir & "\AutoIt3\AutoIt3Help.exe", 0,True)
   _GUICtrlListView_SetImageList($idListview, $hImage, 1)

   _GUICtrlListView_BeginUpdate($idListview)

   ; Add columns
   _GUICtrlListView_AddColumn($idListview, "Items", 350, 1)
   _GUICtrlListView_AddColumn($idListview, "SubItems",100,1)

   ; Add items
   _GUICtrlListView_AddItem($idListview, "blender.exe", 0)
   _GUICtrlListView_AddItem($idListview, "ShareX.exe", 1)
   _GUICtrlListView_AddItem($idListview, "Captvty.exe", 2)
   _GUICtrlListView_AddItem($idListview, "Item 10", 3)
   _GUICtrlListView_AddItem($idListview, "Item 20", 4)
   _GUICtrlListView_AddItem($idListview, "Item 30", 5)
   _GUICtrlListView_AddItem($idListview, "Item 40", 6)

   _GUICtrlListView_AddSubItem($idListview, 0, "C:\Program Files\OpenShot Video Editor\blender\blender.exe", 1)
   _GUICtrlListView_AddSubItem($idListview, 1, "C:\Program Files\ShareX\ShareX.exe", 1)
   _GUICtrlListView_AddSubItem($idListview, 2, "D:\Downloads\captvty-2.6.2\Captvty.exe", 1)
   ; Build groups
   _GUICtrlListView_EnableGroupView($idListview)
   _GUICtrlListView_InsertGroup($idListview, -1, 1, "Group 1",1)
   _GUICtrlListView_InsertGroup($idListview, -1, 2, "Group 2",1)
   _GUICtrlListView_SetItemGroupID($idListview, 0, 1)
   _GUICtrlListView_SetItemGroupID($idListview, 1, 1)
   _GUICtrlListView_SetItemGroupID($idListview, 2, 1)
   _GUICtrlListView_SetItemGroupID($idListview, 3, 2)
   _GUICtrlListView_SetItemGroupID($idListview, 4, 2)
   _GUICtrlListView_SetItemGroupID($idListview, 5, 2)
   _GUICtrlListView_SetItemGroupID($idListview, 6, 2)

   _GUICtrlListView_HideColumn($idListview, 1);on cache la colonne des chemins
   _GUICtrlListView_SetBkColor($idListview, 0x908090)
   _GUICtrlListView_SetTextBkColor($idListview, 0x908090)

   _GUICtrlListView_EndUpdate($idListview)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; Loop until the user exits.
   Do
   Until GUIGetMsg() = $GUI_EVENT_CLOSE
   GUIDelete()
EndFunc   ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
   #forceref $hWnd, $iMsg, $iwParam
   Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $hWndListViewTwo, $tInfo
   $hWndListViewTwo = GUICtrlGetHandle($idListview)
   $hWndH = WinGetHandle($hForm, "")
   $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
   $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
   $iCode = DllStructGetData($tNMHDR, "Code")
   Switch $hWndFrom
      Case $hWndListViewTwo
         Switch $iCode
            Case $NM_DBLCLK
               $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
               $index = DllStructGetData($tInfo, "Index")
               $iIndex = _GUICtrlListView_GetSelectedIndices($hWndFrom) ; ou ($iIDFrom)
               If ($iIndex) <> "" Then
                  If $iIDFrom = $idListview Then
                     $iIndex = Floor($iIndex)
                     $chemin = _GUICtrlListView_GetItemText($idListview, $iIndex, 1)
                     MsgBox(0,"",'ShellExecute("' & $chemin & '")')
                  EndIf
               EndIf
            Case $NM_RCLICK

            Case $NM_CLICK

         EndSwitch
   EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 
J'ai caché les chemins des programmes dans la colonne 2 et il faut double-cliquer
Je vous ai mis plusieurs façons de récupérer les images mais _GUIImageList_AddBitmap() ne prend que les BMP
Idéalement, pour avoir de grandes icones, serait de les récupérer sur le web et de les stoker dans un dossier ou une DLL car en 128 px c'est limite
On peut aussi travailler l'image en GDI+ et utiliser _GUIImageList_Add() (voir l'aide)
Cordialement,
Walkson
"Horas non numero nisi serenas " Le canon de midi
(Je ne compte que les heures heureuses)
Avatar du membre
walkson
Modérateur
Modérateur
Messages : 1020
Enregistré le : ven. 12 août 2011 19:49
Localisation : Hurepoix
Status : Hors ligne

Re: Afficher icônes en grand  

#3

Message par walkson »

On obtient un meilleur résultat avec _GUIImageList_Add()
modifiez _GUIImageList_Add($hImage,ADD("C:\Program Files\Mozilla Firefox\firefox.exe")) si le chemin n'existe pas
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPIShellEx.au3>

Example()

Func Example()
   Global $idListview, $hImage, $hBitmap, $hBMP , $hIcon
   Local $sWow64 = ""
   If @AutoItX64 Then $sWow64 = "\Wow6432Node"
   Local $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\Advanced\Images"

   Global $hForm = GUICreate("ImageList AddBitmap", 400, 600)
   $idListview = GUICtrlCreateListView("", 2, 2, 394, 568, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
   _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
   GUISetState(@SW_SHOW)

   ; Load images
   $hImage = _GUIImageList_Create(128, 128,5)
   _GUIImageList_Add($hImage,ADD("C:\Program Files\Mozilla Firefox\firefox.exe"))
   _GUIImageList_AddBitmap($hImage, $sPath & "\Green.bmp")
   _GUIImageList_AddBitmap($hImage, $sPath & "\Blue.bmp")
   _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110,True)
   _GUIImageList_Add($hImage,ADD(@SystemDir & "\shell32.dll",110))
   _GUIImageList_AddIcon($hImage, @ProgramFilesDir & "\AutoIt3\AutoIt3Help.exe", 0,True)
   _GUIImageList_Add($hImage,ADD(@ProgramFilesDir & "\AutoIt3\AutoIt3Help.exe"))
   _GUICtrlListView_SetImageList($idListview, $hImage, 1)

   _GUICtrlListView_BeginUpdate($idListview)

   ; Add columns
   _GUICtrlListView_AddColumn($idListview, "Items", 350, 1)
   _GUICtrlListView_AddColumn($idListview, "SubItems",100,1)

   ; Add items
   _GUICtrlListView_AddItem($idListview, "blender.exe", 0)
   _GUICtrlListView_AddItem($idListview, "ShareX.exe", 1)
   _GUICtrlListView_AddItem($idListview, "Captvty.exe", 2)
   _GUICtrlListView_AddItem($idListview, "Item 10", 3)
   _GUICtrlListView_AddItem($idListview, "Item 20", 4)
   _GUICtrlListView_AddItem($idListview, "Item 30", 5)
   _GUICtrlListView_AddItem($idListview, "Item 40", 6)

   _GUICtrlListView_AddSubItem($idListview, 0, "C:\Program Files\OpenShot Video Editor\blender\blender.exe", 1)
   _GUICtrlListView_AddSubItem($idListview, 1, "C:\Program Files\ShareX\ShareX.exe", 1)
   _GUICtrlListView_AddSubItem($idListview, 2, "D:\Downloads\captvty-2.6.2\Captvty.exe", 1)
   ; Build groups
   _GUICtrlListView_EnableGroupView($idListview)
   _GUICtrlListView_InsertGroup($idListview, -1, 1, "Group 1",1)
   _GUICtrlListView_InsertGroup($idListview, -1, 2, "Group 2",1)
   _GUICtrlListView_SetItemGroupID($idListview, 0, 1)
   _GUICtrlListView_SetItemGroupID($idListview, 1, 1)
   _GUICtrlListView_SetItemGroupID($idListview, 2, 1)
   _GUICtrlListView_SetItemGroupID($idListview, 3, 2)
   _GUICtrlListView_SetItemGroupID($idListview, 4, 2)
   _GUICtrlListView_SetItemGroupID($idListview, 5, 2)
   _GUICtrlListView_SetItemGroupID($idListview, 6, 2)

   _GUICtrlListView_HideColumn($idListview, 1);on cache la colonne des chemins
   _GUICtrlListView_SetBkColor($idListview, 0xAA90AA)
   _GUICtrlListView_SetTextBkColor($idListview, 0xAA90AA)

   _GUICtrlListView_EndUpdate($idListview)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; Loop until the user exits.
   Do
   Until GUIGetMsg() = $GUI_EVENT_CLOSE
   GUIDelete()
EndFunc   ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
   #forceref $hWnd, $iMsg, $iwParam
   Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $hWndListViewTwo, $tInfo
   $hWndListViewTwo = GUICtrlGetHandle($idListview)
   $hWndH = WinGetHandle($hForm, "")
   $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
   $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
   $iCode = DllStructGetData($tNMHDR, "Code")
   Switch $hWndFrom
      Case $hWndListViewTwo
         Switch $iCode
            Case $NM_DBLCLK
               $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
               $index = DllStructGetData($tInfo, "Index")
               $iIndex = _GUICtrlListView_GetSelectedIndices($hWndFrom) ; ou ($iIDFrom)
               If ($iIndex) <> "" Then
                  If $iIDFrom = $idListview Then
                     $iIndex = Floor($iIndex)
                     $chemin = _GUICtrlListView_GetItemText($idListview, $iIndex, 1)
                     MsgBox(0,"",'ShellExecute("' & $chemin & '")')
                  EndIf
               EndIf
            Case $NM_RCLICK

            Case $NM_CLICK

         EndSwitch
   EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func ADD($Path,$Index_icon = 0, $W = 128, $H = 128)
    _GDIPlus_Startup()

    $hIcon = _WinAPI_ShellExtractIcon($Path, $Index_icon, $W,$H)
   If @error Then Return SetError(1)

    $hBitmap = _GDIPlus_BitmapCreateFromHICON32($hIcon)
   $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
   _WinAPI_DestroyIcon($hIcon)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
Return $hBMP
EndFunc
 
Les icones des EXE restent propres même si elles sont agrandies à plus de 128 px, moins vrai pour les DLL....
Cordialement,
Walkson
"Horas non numero nisi serenas " Le canon de midi
(Je ne compte que les heures heureuses)
micam
Niveau 1
Niveau 1
Messages : 2
Enregistré le : dim. 29 janv. 2017 12:01
Status : Hors ligne

Re: Afficher icônes en grand

#4

Message par micam »

Bonjour walkson.
Fonctionne très bien avec les "exe". Exactement ce que je voulais faire. C'est parfait. Merci de ton aide.
Répondre