Page 1 sur 1
[R] Redimensionnement automatique GUI
Posté : mar. 12 nov. 2013 21:38
par Hugues
Bonjour à tous,
J'ai "bricolé" un petit script pour que mon GUI s'adapte automatiquement à la taille l'écran et en fonction de la barre de tâche (merci jguinch

)...
J'aimerai, si c'est possible que mon gui se redimensionne en "temps réel" lorsque je modifie la taille et la position de ma barre de tâche.
Ci-joint mon code, n'hésitez pas à le critiquer (c'est comme ça qu'on avance ^^).
Merci par avance.
► Afficher le texte
Code : Tout sélectionner
;==[Les Includes]====
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
;==[Déclaration des variables Globale & Autres]====
Global $hGUI
Global $Taskbar = ""
;==[Taille de la barre de tâches pour définir taille de mon GUI]====
Global $aPos = WinGetPos("[CLASS:Shell_TrayWnd]")
Global $Left = $aPos[0]
Global $Right = $aPos[1]
Global $Width = $aPos[2]
Global $Height = $aPos[3]
;==[Détermination de la position de la barre de tâche]====
;Barre de tâche en bas de l'écran
If $Left = 0 And $Width = @DesktopWidth And $Right = (@DesktopHeight - $aPos[3]) Then
$Right = (@DesktopHeight - $aPos[3])
$Taskbar = 1
ConsoleWrite("$TaskbarIsDown" & @CRLF)
EndIf
;Barre de tâche en haut de l'écran
If $Left = 0 And $Width = @DesktopWidth And $Right = 0 Then
$Taskbar = 2
ConsoleWrite("$TaskbarIsUp" & @CRLF)
EndIf
;Barre de tâche à gauche de l'écran
If $Left = 0 And $Right = 0 And $Height = @DesktopHeight Then
$Taskbar = 3
ConsoleWrite("$TaskbarIsLeft" & @CRLF)
EndIf
;Barre de tâche à droite de l'écran
If $Left <> 0 And $Right = 0 And $Height = @DesktopHeight Then
$Taskbar = 4
ConsoleWrite("$TaskbarIsRight" & @CRLF)
EndIf
;Barre de tâche masquée
If $Left = 0 And $Width = @DesktopWidth And $Right = @DesktopHeight - 2 Then
$Taskbar = 5
ConsoleWrite("$TaskbarIsHidden" & @CRLF)
EndIf
_LoadAll()
Func _LoadAll()
;Création de mon GUI en fonction de la position de ma barre de tâche
Select
Case $Taskbar = 1
$hGUI = GUICreate("Down", $Width - 15, ($Right - 48) + 5, 5, 5)
Case $Taskbar = 2
$hGUI = GUICreate("Up", $Width - 15, @DesktopHeight - $Height - 48 + 5, 5, $Height + 5)
Case $Taskbar = 3
$hGUI = GUICreate("Left", @DesktopWidth - $Width - 15, $Height - 44, $Width + 5, 5)
Case $Taskbar = 4
$hGUI = GUICreate("Right", @DesktopWidth - $Width - 15, $Height - 44, 5, 5)
Case $Taskbar = 5
$hGUI = GUICreate("Hidden", @DesktopWidth- 15, @DesktopHeight - $Height, 5, 5)
EndSelect
GUISetState (@SW_SHOW)
GUIRegisterMsg($WM_WINDOWPOSCHANGING, 'WM_WINDOWPOSCHANGING')
WinSetOnTop($hGUI,"",1)
EndFunc
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd
While GUIGetMsg() <> -3
WEnd
Func WM_WINDOWPOSCHANGING($hWnd, $iMsg, $wParam, $lParam)
#forceref $iMsg, $wParam, $lParam
Local $aWinGetPos = WinGetPos($hWnd)
If @error Or $aWinGetPos[0] < -30000 Then Return $GUI_RUNDEFMSG
Local $tWindowPos = DllStructCreate($tagWINDOWPOS, $lParam)
DllStructSetData($tWindowPos, 'X', $aWinGetPos[0])
DllStructSetData($tWindowPos, 'Y', $aWinGetPos[1])
Return $GUI_RUNDEFMSG
EndFunc
Re: [..] Redimensionnement automatique GUI
Posté : mar. 12 nov. 2013 23:44
par jguinch
Salut Hugues.
Un truc comme ça ?
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
Global $hGUI
Global $Taskbar = ""
Global $hGUI = GUICreate("Window", @DesktopWidth, @DesktopHeight, 0, 0)
GUISetState ()
AdlibRegister("_moveGui")
WinSetOnTop($hGUI,"",1)
Func _moveGui()
;==[Taille de la barre de tâches pour définir taille de mon GUI]====
Local $aPos = WinGetPos("[CLASS:Shell_TrayWnd]")
Local $left = $aPos[0]
Local $top = $aPos[1]
Local $Width = $aPos[2]
Local $Height = $aPos[3]
Local $w, $h, $x, $y
;==[Détermination de la position de la barre de tâche]====
;Barre de tâche en bas de l'écran
If $left = 0 And $Width = @DesktopWidth And $top = (@DesktopHeight - $aPos[3]) Then
$w = $width - 10
$h = @DesktopHeight - $height - 10
$x = 5
$y = 5
EndIf
;Barre de tâche en haut de l'écran
If $left= 0 And $Width = @DesktopWidth And $top = 0 Then
$w = $width - 10
$h = @DesktopHeight - $Height - 10
$x = 5
$y = $Height + 5
EndIf
;Barre de tâche à gauche de l'écran
If $left= 0 And $top = 0 And $Height = @DesktopHeight Then
$w = @DesktopWidth - $Width - 10
$h = $Height - 10
$x = $Width + 5
$y = 5
EndIf
;Barre de tâche à droite de l'écran
If $left <> 0 And $top = 0 And $Height = @DesktopHeight Then
$w = @DesktopWidth - $Width - 10
$h = $Height - 10
$x = 5
$y = 5
EndIf
;Barre de tâche masquée
If $left= 0 And $Width = @DesktopWidth And $top = @DesktopHeight - 2 Then
$w = @DesktopWidth - 10
$h = @DesktopHeight - 10
$x = 5
$y = 5
EndIf
Local $aGuiPos = WinGetPos($hGui)
If $aGuiPos[0] <> $x OR $aGuiPos[1] <> $y OR $aGuiPos[2] <> $w OR $aGuiPos[3] <> $h Then WinMove($hGui, "", $x, $y, $w, $h)
EndFunc
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd
Re: [..] Redimensionnement automatique GUI
Posté : mer. 13 nov. 2013 12:20
par Hugues
Oh yeah!!
Merci beaucoup de ton aide.
Sujet résolu!
Re: [R] Redimensionnement automatique GUI
Posté : jeu. 14 nov. 2013 14:04
par TommyDDR
Un peu moins long :
► Afficher le textecode
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
Global $hGUI = GUICreate("Window", @DesktopWidth, @DesktopHeight, 0, 0)
GUISetState()
AdlibRegister("_moveGui")
WinSetOnTop($hGUI, "", 1)
While(True)
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd
Func _moveGui()
Local $WorkAera = GetWorkArea()
Local $aGuiPos = WinGetPos($hGui)
If $aGuiPos[0] <> $WorkAera[0] OR $aGuiPos[1] <> $WorkAera[1] OR $aGuiPos[2] <> $WorkAera[4] OR $aGuiPos[3] <> $WorkAera[5] Then WinMove($hGui, "", $WorkAera[0], $WorkAera[1], $WorkAera[4], $WorkAera[5])
EndFunc
Func GetWorkArea()
Local $Area[6]
Local $StartRect = DllStructCreate("int[4]")
Local $PStartRect = DllStructGetPtr($StartRect)
Local $res = DllCall("user32.dll", "int", "SystemParametersInfo", "int", 48, "int", 0, "ptr", $PStartRect, "int", 0)
$Area[0] = DllStructGetData($StartRect,1,1)
$Area[1] = DllStructGetData($StartRect,1,2)
$Area[2] = DllStructGetData($StartRect,1,3)
$Area[3] = DllStructGetData($StartRect,1,4)
$Area[4] = $Area[2] - $Area[0]
$Area[5] = $Area[3] - $Area[1]
Return $Area
EndFunc
Re: [R] Redimensionnement automatique GUI
Posté : jeu. 14 nov. 2013 14:32
par jguinch
@TommyDDR : ah oui, c'est beaucoup mieux !
Merci, je garde
Re: [R] Redimensionnement automatique GUI
Posté : lun. 10 août 2015 23:32
par mdanielm
Salut,
Et, pourquoi pas remplacer
Code : Tout sélectionner
While(True)
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd
par:
Re: [R] Redimensionnement automatique GUI
Posté : mar. 11 août 2015 01:07
par jchd
Peut-être parce que dans le second cas il n'y a plus de variable $msg pour poursuivre les autres Case si par exemple on doit gérer du code réaliste.
Re: [R] Redimensionnement automatique GUI
Posté : mer. 12 août 2015 15:10
par mdanielm
Ben alors:
Code : Tout sélectionner
$msg = GUIGetMsg()
While ($msg <> $GUI_EVENT_CLOSE)
Select
-------
--------
EndSelect
$msg = GUIGetMsg()
wend
; dire au revoir?