Image PNG déformé avec TraySetState quand on revient sur la GUI

Aide sur les Interfaces Graphique Utilisateurs (GUI).
Règles du forum
.
Répondre
Avatar du membre
LaTMoT
Niveau 1
Niveau 1
Messages : 12
Enregistré le : ven. 15 sept. 2017 14:33
Localisation : Eure et Loir
Status : Hors ligne

Image PNG déformé avec TraySetState quand on revient sur la GUI

#1

Message par LaTMoT »

Bonjour,

Me revoilà ;-)

J'ai une image qui s'affiche dans une GUI et quand je clique 2 fois sur l'icone dans la barre des tâches l'image se déforme et je ne comprend pas du tout pourquoi.

Pourriez-vous, s'il vous plaît, m'aider ?

Merci.

Précision : Code allégé pour le forum, je n'ai laissé que le minimum, normalement l'image change suivant la sélection dans un menu déroulant. Plusieurs tailles d'images possible.

ACDC-Logo-Band.png
ACDC-Logo-Band.png (10.06 Kio) Vu 70365 fois

Code : Tout sélectionner

#include <Array.au3>
#include <AutoItConstants.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <file.au3>
#include <FontConstants.au3>
#include <GDIPlus.au3>
#include <GuiComboBox.au3>
#include <GuiConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiScrollBars.au3>
#include <GuiStatusBar.au3>
#include <Math.au3>
#include <MsgBoxConstants.au3>
#include <ScrollBarConstants.au3>
#include <StaticConstants.au3>
#include <TrayConstants.au3>
#include <StringConstants.au3>
#include <WindowsConstants.au3>

;~ DECLARATION DES VARIABLES GLOBALES
	Global $hImage, $hGraphic, $aArray, $iRows, $iCols

;~ CREATION DE LA FENETRE PRINCIPALE
	Global $MyTabsGui = GUICreate("GUI", 900, 600, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_WINDOWEDGE + $WS_EX_APPWINDOW) ; FENETRE
	TraySetState($TRAY_ICONSTATE_SHOW)
	GUISetBkColor($COLOR_WHITE) ; FOND BLANC

	;~ CREATION DU BUTTON QUITTER
		$idButtonClose = GUICtrlCreateButton("Quitter", 858, 1, 40, 40, $BS_ICON)
		GUICtrlSetImage(-1, "shell32.dll", 28)

	;~ CREATION EMPLACEMENT IMAGE LOGO BAND
		Local $pic = GUICtrlCreateLabel("", 50, 1, 350, 39, $SS_BITMAP)
		GUICtrlSetBkColor(-1, $COLOR_WHITE)

GUISetState(@SW_SHOW, $MyTabsGui)

SetImageBand() ; FUNC QUI AFFICHE LE LOGO DE L'ARTISTE

While 1
	$msg = GUIGetMsg()
	Select
		Case $msg = $GUI_EVENT_CLOSE
			_do_exit_stuff()
		Case $msg = $idButtonClose
			ExitLoop
    EndSelect
WEnd

Func _do_exit_stuff()

        ; CE QUE JE VEUX QUAND LE PROGRAMME SE FERME

        Exit

EndFunc   ;==>_do_exit_stuff

;~ FUNC QUI AFFICHE LE LOGO DE L'ARTISTE DANS LA GUI
Func SetImageBand()
;~ 	AFFICHE LE LOGO
	$file = @ScriptDir & "\ACDC-Logo-Band.png"
	If FileExists($file) = 0 Then
		GUICtrlSendMsg($pic, $STM_SETIMAGE, $IMAGE_BITMAP, 0) ; supprime l'image si elle existe
		Return SetError(1)
	EndIf
	$img = ADD_image($file)
;~ 	MsgBox(0, "handle Hbitmap existe", $img)
	$hb = GUICtrlSendMsg($pic, $STM_SETIMAGE, $IMAGE_BITMAP, $img)
	If $hb Then _WinAPI_DeleteObject($hb)
	_WinAPI_DeleteObject($img)

EndFunc   ;==>SetImageBand

Func ADD_image($sFile) ;crer un Hbitmap selon chemin
        _GDIPlus_Startup()
        $hBitmap = _GDIPlus_BitmapCreateFromFile($sFile) ; charge image
        $W = _GDIPlus_ImageGetWidth($hBitmap)
        $H = _GDIPlus_ImageGetHeight($hBitmap)
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;crée un graphic selon l'image
        _GDIPlus_GraphicsSetCompositingQuality($hGraphic, 2) ;améliore la qualité non indispensable
        _GDIPlus_GraphicsSetInterpolationMode($hGraphic, 7) ;améliore la qualité non indispensable
        _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;améliore la qualité non indispensable
        _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hBitmap, 0, 0, $W, $H, 0, 0, $W, $H) ;dessine l'image dans le graphic
        $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;crée un Hbitmap adaptable au menu à partir du bitmap
        _GDIPlus_BitmapDispose($hBitmap) ;nettoie
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
        Return $hBMP ;retourne le handle du Hbitmap
EndFunc   ;==>ADD_image
Laurent, débutant avec AutoIt :-)

Projet AutoIt en cours : Gestion de mes Tablatures Guitare avec Vidéos des cours.
Avatar du membre
mikell
Spammer !
Spammer !
Messages : 6292
Enregistré le : dim. 29 mai 2011 17:32
Localisation : Deep Cévennes
Status : Hors ligne

Re: Image PNG déformé avec TraySetState quand on revient sur la GUI  

#2

Message par mikell »

Il y a plusieurs manières de gérer ça, qui dépendent de comment tu utilises les fonctions lors du fonctionnement du script
Par exemple, si tu appelles la fonction SetImageBand() à chaque fois que tu affiches une image différente, alors le plus simple - et de loin - est de rajouter cette ligne dans la fonction ADD_image() :

        $W = _GDIPlus_ImageGetWidth($hBitmap)
        $H = _GDIPlus_ImageGetHeight($hBitmap)
        GUICtrlSetPos ($pic, 50, 1, $W, $H)  ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
ça redimensionne dès le départ le contrôle à la taille de l'image à utiliser et hop t'es plus emm...bêté :wink:
" L'échec est le fondement de la réussite. " (Lao-Tseu )
" Plus ça rate, plus on a de chances que ça marche " (les Shadoks )
Avatar du membre
LaTMoT
Niveau 1
Niveau 1
Messages : 12
Enregistré le : ven. 15 sept. 2017 14:33
Localisation : Eure et Loir
Status : Hors ligne

Re: Image PNG déformé avec TraySetState quand on revient sur la GUI

#3

Message par LaTMoT »

Bonjour,

Merci à toi cela fonctionne bien maintenant :D

Suis juste déçu de ne pas avoir trouver tout seul :wink:

Encore merci.
Laurent, débutant avec AutoIt :-)

Projet AutoIt en cours : Gestion de mes Tablatures Guitare avec Vidéos des cours.
Répondre