Page 1 sur 1

[Ex] WinSetIcon

Posté : mer. 13 févr. 2013 22:17
par mikell
Suite à ce sujet : http://www.autoitscript.fr/forum/viewto ... =3&t=10897
Voilà l'exemple d'une petite fonction qui permet de changer l'icone de la barre de titre d'une fenêtre d'application non-autoit

Code : Tout sélectionner

#include <WinAPI.au3>

ShellExecute(StringRegExpReplace(@Autoitexe, '(.+)\\[^\\]+', "$1") & "\AutoIt.chm")
Do
  Sleep(10)
Until WinExists("AutoIt Help") 
$handle = WinGetHandle("AutoIt Help") 

; $ico = @scriptdir & "\autoitfr.ico"
; _WinSetIcon($handle, $ico)

_WinSetIcon($handle, "shell32.dll", 137)

WinSetTitle($handle, "", "AutoIt Help with niou icone") 

;=========================================
Func _WinSetIcon($hwnd, $file, $index = 0) 
    Local $tIcons = DllStructCreate("ptr Data")
    DllCall("shell32.dll", "uint", "ExtractIconExW", "wstr", $file, "int", $index, "struct*", 0, "struct*", $tIcons, "uint", 1)
    If @error Then Return SetError(1, 0, 0)
    Local $hicon = DllStructGetData($tIcons, "Data")
   _SendMessage($hwnd, 0x0080, 1, $hicon ) ;$WM_SETICON = 0x0080
   _WinAPI_DestroyIcon($hicon)
EndFunc
 

Re: [Ex] WinSetIcon

Posté : mer. 13 févr. 2013 22:51
par matwachich
mmm j'aime!
Je la garde à porté de main celle-la.

PS: Je vais juste la modifié pour ne pas être dépendante de WinAPI
PS2: niou icone :lol:

Re: [Ex] WinSetIcon

Posté : lun. 13 avr. 2015 18:01
par ZDS
Bonjour,

Juste une retouche car un bug est présent si on détruit l'icone directement. Un simple Sleep(250) fait l'affaire (sinon, pixelisation de l'icone en 16x16 quand elle est affichée en 32x32 dans la barre des tâches) :

Code : Tout sélectionner

Func _WinSetIcon($hwnd, $file, $index = 0) 
    Local $tIcons = DllStructCreate("ptr Data")
    DllCall("shell32.dll", "uint", "ExtractIconExW", "wstr", $file, "int", $index, "struct*", 0, "struct*", $tIcons, "uint", 1)
    If @error Then Return SetError(1, 0, 0)
    Local $hicon = DllStructGetData($tIcons, "Data")
   _SendMessage($hwnd, 0x0080, 1, $hicon ) ;$WM_SETICON = 0x0080
   Sleep(250)
   _WinAPI_DestroyIcon($hicon)
EndFunc
► Afficher le texteAutre version pour un fichier *.ico en chemin direct
A bientôt; et encore merci :)

Re: [Ex] WinSetIcon

Posté : lun. 13 avr. 2015 20:57
par jguinch
Peut-être plus simple : mettre le _WinAPI_DestroyIcon en sortie de script ? (mais je ne sais pas si ça peut avoir une incidence sur le reste..