Page 1 sur 1

[R] Multiples GUI avec GUIRegisterMsg

Posté : sam. 05 sept. 2020 07:14
par julienG
Bonjour,

Suite à de multiples recherches sans trouver de solution, je tente ma chance sur ce forum.

Dans une première GUI équipée d'un listview, lorsque je clic sur le listview, je veux ouvrir une seconde GUI.
Pour détecter le clic dans le listview, j'utilise la méthode GUIRegisterMsg avec VMCOMMAND, malheureusement cette méthode me fait planter mon script à l'ouverture de la seconde GUI ( celle-ci ne se charge pas et fait planter le script).

Est-ce que quelqu’un à déjà vu ce phénomène? est-ce une limitation de l'autoit?

Mon code:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>



#Region ### START Koda GUI section ### Form=c:\users\emili\desktop\logiciel\koda\accueil.kxf
$softinfi = GUICreate("SOFTINFI", 615, 437, 192, 124)
$ListePatient = GUICtrlCreateList("", 32, 72, 369, 305)
$Label1 = GUICtrlCreateLabel("Liste des patients de la tournée de  Emilie Jacquet", 32, 32, 359, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$BTAjoutPatient = GUICtrlCreateButton("Ajouter un patient", 424, 104, 161, 41)
$BTGenerPlanning = GUICtrlCreateButton("Générer planning", 424, 160, 161, 41)
$BtVoirPlanning = GUICtrlCreateButton("Voir planning du jour", 424, 216, 161, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

liste_patient()


While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      case $BTAjoutPatient
         GUI_FichePatient()
   EndSwitch
WEnd


func liste_patient()
   GUICtrlSetData ( $ListePatient, "TOTO")

endfunc


func liste_patient_onclick()

      GUI_FichePatient()

endfunc


func GUI_FichePatient()
#Region ### START Koda GUI section ### Form=c:\users\emili\desktop\logiciel\koda\ajoutpatient.kxf
$fichepatient = GUICreate("Fiche Patient", 543, 585, 193, 125)
$Label1 = GUICtrlCreateLabel("Fiche Patient", 184, 24, 193, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit

   EndSwitch
WEnd

endfunc


; interception des actions sur les objets
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

Local $nNotifyCode = _HiWord($wParam)
Local $nID = _LoWord($wParam)
Local $hCtrl = $lParam
;local Const $CBN_EDITCHANGE = 5
local Const $CBN_SELCHANGE = 1
;local Const $CBN_EDITUPDATE = 6
;local Const $LABEL_EDITCHANGE = 1024
;local Const $LABEL_EDITUPDATE = 768


Switch $nID
case $Listepatient
switch $nNotifyCode

case $CBN_SELCHANGE

liste_patient_onclick()
EndSwitch
EndSwitch
endfunc


Func _HiWord($x)
Return BitShift($x, 16)
EndFunc ;==>_HiWord

Func _LoWord($x)
Return BitAND($x, 0xFFFF)
EndFunc ;==>_LoWord
Merci à la personne qui pourra me donner une piste ou au moins m'expliquer ce qui ne fonctionne pas.

Cordialement

Re: Multiples GUI avec GUIRegisterMsg

Posté : sam. 05 sept. 2020 11:22
par mikell
Pas besoin de WM_COMMAND pour ça. Vaut mieux faire simple
Et ce que tu utilises n'est pas un controle Listview, c'est un controle Listbox
Par contre tu vas te retrouver avec 2 gui, il faut pouvoir les gérer séparément => tutorial

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $fichepatient = -1

$softinfi = GUICreate("SOFTINFI", 615, 437, 192, 124)
$ListePatient = GUICtrlCreateList("", 32, 72, 369, 305)
$Label1 = GUICtrlCreateLabel("Liste des patients de la tournée de  Emilie Jacquet", 32, 32, 359, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$BTAjoutPatient = GUICtrlCreateButton("Ajouter un patient", 424, 104, 161, 41)
$BTGenerPlanning = GUICtrlCreateButton("Générer planning", 424, 160, 161, 41)
$BtVoirPlanning = GUICtrlCreateButton("Voir planning du jour", 424, 216, 161, 41)
GUISetState(@SW_SHOW)

liste_patient()

While 1
   $nMsg = GUIGetMsg(1)
   Switch $nMsg[0]
      Case $GUI_EVENT_CLOSE
         If $nMsg[1] = $softinfi Then Exit
         If $nMsg[1] = $fichepatient Then GuiDelete($fichepatient)
      case $BTAjoutPatient
         GUI_FichePatient("new")
      case $ListePatient
          $patient = GuiCtrlRead($ListePatient)
          If $patient <> "" Then liste_patient_onclick($patient)
   EndSwitch
WEnd

func liste_patient()
   GUICtrlSetData ( $ListePatient, "TOTO|Marcel")
endfunc

func liste_patient_onclick($patient)
      GUI_FichePatient($patient)
endfunc

func GUI_FichePatient($patient)
GuiDelete($fichepatient)
$fichepatient = GUICreate("Fiche Patient " & $patient, 543, 585, 193, 125)
$Label1 = GUICtrlCreateLabel("Fiche Patient " & $patient, 184, 24, 193, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
endfunc

Re: Multiples GUI avec GUIRegisterMsg

Posté : sam. 05 sept. 2020 21:40
par julienG
Bonjour Mikell,

Merci beaucoup pour ton aide, je met le sujet en résolu.
Peux-tu juste me dire la différence entre une listbox et un listview? je ne trouve pas la différence sur le net.

Re: Multiples GUI avec GUIRegisterMsg

Posté : dim. 06 sept. 2020 09:54
par walkson
Bonjour,
julienG a écrit : sam. 05 sept. 2020 21:40 Peux-tu juste me dire la différence entre une listbox et un listview? je ne trouve pas la différence sur le net.
Sincèrement vous n'avez pas beaucoup cherché :P
https://www.autoitscript.fr/autoit3/doc ... stView.htm
https://www.autoitscript.fr/autoit3/doc ... Create.htm
Dans le code, au centre une listview et aux extrémités des listboxs (pour voir la différence)

Code : Tout sélectionner

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 615, 320)
Global $List1 = GUICtrlCreateList("", 16, 56, 129, 201);Advanced (Class):	[CLASS:ListBox; INSTANCE:1]
GUICtrlSetData(-1, "aa|bb|cc")
Global $ListView1 = GUICtrlCreateListView("0|1|2|", 168, 56, 193, 201);Advanced (Class):	[CLASS:SysListView32; INSTANCE:1]
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 50)
Global $ListView1_0 = GUICtrlCreateListViewItem("aa|aa1|aa2", $ListView1)
Global $ListView1_1 = GUICtrlCreateListViewItem("bb|bb1|bb2", $ListView1)
Global $ListView1_2 = GUICtrlCreateListViewItem("cc|cc1|cc2", $ListView1)
$idListBox = _GUICtrlListBox_Create($Form1, "String upon creation", 380, 56, 192, 214, BitOR($LBS_STANDARD, $LBS_MULTICOLUMN),$WS_EX_DLGMODALFRAME);Advanced (Class):	[CLASS:ListBox; INSTANCE:2]
	; Set the width of the columns
	_GUICtrlListBox_SetColumnWidth($idListBox, 50)

	; Add strings
	_GUICtrlListBox_BeginUpdate($idListBox)
	For $iI = 1 To 50
		_GUICtrlListBox_AddString($idListBox, StringFormat("Item %03d", $iI))
	Next
	_GUICtrlListBox_EndUpdate($idListBox)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit

 EndSwitch
WEnd
Voir aussi dans l'aide _GUICtrlListView_Create() et autres

Re: [R] Multiples GUI avec GUIRegisterMsg

Posté : dim. 06 sept. 2020 14:40
par julienG
Merci pour la réponse,
en faite le listeview est beaucoup plus complet qu'un simple listbox.

Par contre en remplaçant mon listBox par une listview, j'ai toujours le problème d'origine qui ne me permet pas d'ouvrir une seconde GUI.

Re: [R] Multiples GUI avec GUIRegisterMsg

Posté : dim. 06 sept. 2020 16:02
par walkson
C'est la construction du code qui ne va pas avec WM_COMMAND (je répondais au message que vous avez supprimé :wink: )
Si vous utilisez listview, il faut utilisé WM_NOTIFY
Une proposition de code avec Listbox

Code : Tout sélectionner

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>



#Region ### START Koda GUI section ### Form=c:\users\emili\desktop\logiciel\koda\accueil.kxf
$softinfi = GUICreate("SOFTINFI", 615, 437, 192, 124)
$ListePatient = GUICtrlCreateList("", 32, 72, 369, 305)
Global $hList1 = GUICtrlGetHandle($ListePatient)
$Label1 = GUICtrlCreateLabel("Liste des patients de la tournée de  Emilie Jacquet", 32, 32, 359, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$BTAjoutPatient = GUICtrlCreateButton("Ajouter un patient", 424, 104, 161, 41)
$BTGenerPlanning = GUICtrlCreateButton("Générer planning", 424, 160, 161, 41)
$BtVoirPlanning = GUICtrlCreateButton("Voir planning du jour", 424, 216, 161, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

liste_patient()

Global $fichepatient, $Label2
While 1
   $nMsg = GUIGetMsg(1)
   Switch $nMsg[1]
	   Case $softinfi
		   Switch $nMsg[0]
			  Case $GUI_EVENT_CLOSE
				 Exit
			  case $BTAjoutPatient
				 GUI_FichePatient()
		   EndSwitch
	   Case $fichepatient
		   Switch $nMsg[0]
			  Case $GUI_EVENT_CLOSE
				 GUIDelete($fichepatient)
		   EndSwitch

   EndSwitch
WEnd


func liste_patient()
   GUICtrlSetData ( $ListePatient, "TOTO|MAC")

endfunc


func liste_patient_onclick()

      GUI_FichePatient()

endfunc


func GUI_FichePatient()
#Region ### START Koda GUI section ### Form=c:\users\emili\desktop\logiciel\koda\ajoutpatient.kxf
$fichepatient = GUICreate("Fiche Patient", 543, 585, 193, 125)
$Label1 = GUICtrlCreateLabel("Fiche Patient", 184, 24, 193, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("", 184, 50, 193, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

endfunc


; interception des actions sur les objets
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

Local $nNotifyCode = _HiWord($wParam)
Local $nID = _LoWord($wParam)
Local $hCtrl = $lParam

Switch $hCtrl
	case $hList1
		switch $nNotifyCode
			case $LBN_SELCHANGE ;listbox
				liste_patient_onclick()
				GUICtrlSetData($Label2,GUICtrlRead($nID) )
		EndSwitch
	EndSwitch
endfunc


Func _HiWord($x)
Return BitShift($x, 16)
EndFunc ;==>_HiWord

Func _LoWord($x)
Return BitAND($x, 0xFFFF)
EndFunc ;==>_LoWord

Re: [R] Multiples GUI avec GUIRegisterMsg

Posté : dim. 06 sept. 2020 17:39
par mikell
julienG a écrit : dim. 06 sept. 2020 14:40en faite le listeview est beaucoup plus complet qu'un simple listbox
"plus complet" ça ne veut pas dire grand'chose, tout dépend de l'usage souhaité. Pour afficher plusieurs infos sur une même ligne, listview est plus adapté. Pour afficher une liste de patients, listbox suffit largement vu que les infos détaillées figureront sur la fiche

épi quand même, ça serait sympa de répondre à la question posée dans le 1er post à propos du crash :mrgreen:
Dans le script posté, ce crash est provoqué par la fonction lancée dans WM_COMMAND. Cette fonction contient une boucle While qui est blocante et qui empêche de sortir proprement du WM_COMMAND, du coup les messages Windows ne passent plus
Comme le dit le fichier d'aide (notre bible à tous) pour GUIRegisterMsg :
Warning: blocking of running user functions which executes window messages (...) can lead to unexpected behavior, the return to the system should be as fast as possible !!!
Image
Dans le script de walkson, la fonction dans WM_COMMAND ne fait que créer la 2ème gui, et c'est la boucle While principale qui gère cette gui - donc ça marche

Re: [R] Multiples GUI avec GUIRegisterMsg

Posté : dim. 06 sept. 2020 21:29
par julienG
Mikell,

Merci pour les explications, effectivement il ya une logique à ce problème. Je passe pas mal de temps dans l'aide mais elle est très complète et vaste, ce qui est un gros avantage mais parfois je passe à coté de certains points de détails...

Walkson,

merci pour les explications et l'exemple.
Par contre dans ton exemple, si je rajoute un bouton dans ma seconde GUI et que je souhaite le gérer à partir de la première boucle While, le bouton est insta déclenché à l'ouverture de la première GUI.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>



#Region ### START Koda GUI section ### Form=c:\users\emili\desktop\logiciel\koda\accueil.kxf
$softinfi = GUICreate("SOFTINFI", 615, 437, 192, 124)
$ListePatient = GUICtrlCreateList("", 32, 72, 369, 305)
Global $hList1 = GUICtrlGetHandle($ListePatient)
$Label1 = GUICtrlCreateLabel("Liste des patients de la tournée de  Emilie Jacquet", 32, 32, 359, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$BTAjoutPatient = GUICtrlCreateButton("Ajouter un patient", 424, 104, 161, 41)
$BTGenerPlanning = GUICtrlCreateButton("Générer planning", 424, 160, 161, 41)
$BtVoirPlanning = GUICtrlCreateButton("Voir planning du jour", 424, 216, 161, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

liste_patient()

Global $fichepatient, $Label2, $validerpat
While 1
   $nMsg = GUIGetMsg(1)
   Switch $nMsg[1]
      Case $softinfi
         Switch $nMsg[0]
           Case $GUI_EVENT_CLOSE
             Exit
           case $BTAjoutPatient
             GUI_FichePatient()
         EndSwitch
      Case $fichepatient
         Switch $nMsg[0]
           Case $GUI_EVENT_CLOSE
             GUIDelete($fichepatient)
            case $validerpat
               msgbox(0,'','test')
         EndSwitch

   EndSwitch
WEnd


func liste_patient()
   GUICtrlSetData ( $ListePatient, "TOTO|MAC")

endfunc


func liste_patient_onclick()

      GUI_FichePatient()

endfunc


func GUI_FichePatient()
#Region ### START Koda GUI section ### Form=c:\users\emili\desktop\logiciel\koda\ajoutpatient.kxf
$fichepatient = GUICreate("Fiche Patient", 543, 585, 193, 125)
$Label1 = GUICtrlCreateLabel("Fiche Patient", 184, 24, 193, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("", 184, 50, 193, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$validerpat = GUICtrlCreateButton("VALIDER", 120, 520, 129, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

endfunc


; interception des actions sur les objets
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

Local $nNotifyCode = _HiWord($wParam)
Local $nID = _LoWord($wParam)
Local $hCtrl = $lParam

Switch $hCtrl
   case $hList1
      switch $nNotifyCode
         case $LBN_SELCHANGE ;listbox
            liste_patient_onclick()
            GUICtrlSetData($Label2,GUICtrlRead($nID) )
      EndSwitch
   EndSwitch
endfunc


Func _HiWord($x)
Return BitShift($x, 16)
EndFunc ;==>_HiWord

Func _LoWord($x)
Return BitAND($x, 0xFFFF)
EndFunc ;==>_LoWord
Encore merci à vous 2.

Re: [R] Multiples GUI avec GUIRegisterMsg

Posté : lun. 07 sept. 2020 01:20
par walkson
C'est parce que $fichepatient renvoie 0 car il n'existe pas. Pour résoudre le problème il faut déclarer Global $fichepatient = -1
On peut aussi lancer la deuxième gui pour lui donner sa valeur en Hide avant la boucle et jouer entre hide et show pour afficher la gui

Code : Tout sélectionner

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>



#Region ### START Koda GUI section ### Form=c:\users\emili\desktop\logiciel\koda\accueil.kxf
$softinfi = GUICreate("SOFTINFI", 615, 437, 192, 124)
$ListePatient = GUICtrlCreateList("", 32, 72, 369, 305)
Global $hList1 = GUICtrlGetHandle($ListePatient)
$Label1 = GUICtrlCreateLabel("Liste des patients de la tournée de  Emilie Jacquet", 32, 32, 359, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$BTAjoutPatient = GUICtrlCreateButton("Ajouter un patient", 424, 104, 161, 41)
$BTGenerPlanning = GUICtrlCreateButton("Générer planning", 424, 160, 161, 41)
$BtVoirPlanning = GUICtrlCreateButton("Voir planning du jour", 424, 216, 161, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

liste_patient()

Global $fichepatient, $Label2, $validerpat
GUI_FichePatient()
While 1
   $nMsg = GUIGetMsg(1)
   Switch $nMsg[1]
      Case $softinfi
         Switch $nMsg[0]
           Case $GUI_EVENT_CLOSE
             Exit
           case $BTAjoutPatient
             GUI_FichePatient()
         EndSwitch
      Case $fichepatient
         Switch $nMsg[0]
           Case $GUI_EVENT_CLOSE
             GUISetState(@SW_HIDE,$fichepatient)
            case $validerpat
               msgbox(0,'','test')
         EndSwitch

   EndSwitch
WEnd


func liste_patient()
   GUICtrlSetData ( $ListePatient, "TOTO|MAC")

endfunc


func liste_patient_onclick()

	  GUISetState(@SW_SHOW,$fichepatient)

endfunc


func GUI_FichePatient()
#Region ### START Koda GUI section ### Form=c:\users\emili\desktop\logiciel\koda\ajoutpatient.kxf
$fichepatient = GUICreate("Fiche Patient", 543, 585, 193, 125)
$Label1 = GUICtrlCreateLabel("Fiche Patient", 184, 24, 193, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("", 184, 50, 193, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$validerpat = GUICtrlCreateButton("VALIDER", 120, 520, 129, 33)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

endfunc


; interception des actions sur les objets
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

Local $nNotifyCode = _HiWord($wParam)
Local $nID = _LoWord($wParam)
Local $hCtrl = $lParam

Switch $hCtrl
   case $hList1
      switch $nNotifyCode
         case $LBN_SELCHANGE ;listbox
            liste_patient_onclick()
            GUICtrlSetData($Label2,GUICtrlRead($nID) )
      EndSwitch
   EndSwitch
endfunc


Func _HiWord($x)
Return BitShift($x, 16)
EndFunc ;==>_HiWord

Func _LoWord($x)
Return BitAND($x, 0xFFFF)
EndFunc ;==>_LoWord
Personnellement quand je dois gérer plusieurs guis, j'utilise le mode événementiel. C'est plus simple mais c'est plus long