ermar Posted September 10 Posted September 10 Hi all, I'm tearing my hair out once again trying to display a new window (listview) from a previous process, waiting for a “yes” response to continue the script, otherwise we abandon it. A kind of custom _arraydisplay where I perform processing using the listview (using the awesome UDF GuilistviewEx from Melba). I try to have wait for the loop that allows me to choose between continuing, or abandoning, because the script continues in my function I find it confusing to manage this second window. To illustrate the issue, here is a script that simulates the problem when the Process button "Traitement" is clicked : The Listview appears but the folllowing script continues and display the message box. Thank you for the help. Regards Eric GuiMultiple.au3
Developers Jos Posted September 10 Developers Posted September 10 Moved to the appropriate AutoIt General Help and Support forum, as the AutoIt Example Scripts forum very clearly states: Quote Share your cool AutoIt scripts, UDFs and applications with others. Do not post general support questions here, instead use the AutoIt Help and Support forums. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
MattyD Posted September 11 Posted September 11 Hi Eric, If I'm understanding this correctly, you're trying to "pause" the script from within gui2()? That's problematic because gui2() is being called from an event handler. And until that handler returns, you're blocking further messages from being processed. so maybe something like this?? expandcollapse popup#AutoIt3Wrapper_UseX64=Y #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <MsgBoxConstants.au3> #include <Array.au3> #include <GuiMenu.au3> #include <GuiListView.au3> #include <EditConstants.au3> Opt("GUIOnEventMode", 1) Global $g_hGUI1, $g_hGUI2, $g_idButton1, $g_idButton2, $g_idButton3 Global $hListViewDatascope, $hDatabaseScope, $Button1, $Button2 ;a utiliser pour l'affichage de la 2eme fenetre Global $iEditMode = 0 gui1() While WinExists($g_hGUI1) If $g_hGUI2 And WinExists($g_hGUI2) Then GUISetState(@SW_DISABLE, $g_hGUI1) While WinExists($g_hGUI2) Sleep(10) WEnd GUISetState(@SW_ENABLE, $g_hGUI1) MsgBox(0, "Suite", "cela continue") ;suite du script EndIf Sleep(10) WEnd Func gui1() $g_hGUI1 = GUICreate("GUI 1", 200, 200, 100, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") ; Call a common GUI close function $g_idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30) GUICtrlSetOnEvent(-1, "On_Button") ; Call a common button function $g_idButton2 = GUICtrlCreateButton("Show GUI 2", 10, 60, 80, 30) GUICtrlSetOnEvent(-1, "On_Button") ; Call a common button function $g_idButton3 = GUICtrlCreateButton("Traitement", 10, 100, 80, 30) GUICtrlSetOnEvent(-1, "Traitement_intermediaire") ; Call a traitement GUISetState() EndFunc ;==>gui1 Func gui2() $g_hGUI2 = GUICreate("GUI 2", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") ; Call a common GUI close function $g_idButton3 = GUICtrlCreateButton("GoOn", 10, 450, 100, 30) GUICtrlSetOnEvent(-1, "On_Button") ; Call a common button function $g_idButton4 = GUICtrlCreateButton("Cancel", 250, 450, 100, 30) GUICtrlSetOnEvent(-1, "Off_Button") ; Call a common button function $hListViewDatascope = GUICtrlCreateListView("Tom|Dick|Harry", 10, 10, 400, 400, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetExtendedListViewStyle($hListViewDatascope, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) _GUICtrlListView_SetColumnWidth($hListViewDatascope, 0, 93) _GUICtrlListView_SetColumnWidth($hListViewDatascope, 1, 93) _GUICtrlListView_SetColumnWidth($hListViewDatascope, 2, 93) ; Set font GUICtrlSetFont($hListViewDatascope, 12, Default, Default, "Courier New") ; Note edit control will use same font ; Create array and fill listview Global $aLV_List[20] For $i = 0 To UBound($aLV_List) - 1 If Mod($i, 5) Then $aLV_List[$i] = "Tom " & $i & "|Dick " & $i & "|Harry " & $i Else $aLV_List[$i] = "Tom " & $i & "||Harry " & $i EndIf GUICtrlCreateListViewItem($aLV_List[$i], $hListViewDatascope) Next ;_GUIListViewEx_Init($hLV, $aArray = "", $iStart = 0, $iColour = 0, $fImage = False, $iAdded = 0) $iLVIndex_1 = _GUIListViewEx_Init($hListViewDatascope, $aLV_List, 0, 0, True, +1 + 4) ; Tri & modification possible ;_GUIListViewEx_SetEditStatus($iLV_Index, $vCol, $iMode = 1, $vParam1 = Default, $vParam2 = Default) _GUIListViewEx_SetEditStatus($iLVIndex_1, "1;2") ;modification des colonnes 1 & 2 _GUIListViewEx_SetActive($iLVIndex_1) ; Enregistrement des messages Windows _GUIListViewEx_MsgRegister(Default) GUIRegisterMsg($WM_NOTIFY, "_Events_WM_NOTIFY") GUISetState() EndFunc ;==>gui2 Func On_Close() Switch @GUI_WinHandle ; See which GUI sent the CLOSE message Case $g_hGUI1 Exit ; If it was this GUI - we exit <<<<<<<<<<<<<<< Case $g_hGUI2 GUIDelete($g_hGUI2) ; If it was this GUI - we just delete the GUI <<<<<<<<<<<<<<< GUICtrlSetState($g_idButton2, $GUI_ENABLE) EndSwitch EndFunc ;==>On_Close Func Off_Button() On_Close() EndFunc ;==>Off_Button Func On_Button() Switch @GUI_CtrlId ; See which button sent the message Case $g_idButton1 MessageBox(1) ; We can call a function with parameters here <<<<<<<<<<<<<<<<<<< Case $g_idButton2 GUICtrlSetState($g_idButton2, $GUI_DISABLE) gui2() Case $g_idButton3 MessageBox(2) ; We can call a function with parameters here <<<<<<<<<<<<<<<<<<< EndSwitch EndFunc ;==>On_Button Func MessageBox($iIndex) MsgBox($MB_OK, "MsgBox " & $iIndex, "Test from Gui " & $iIndex) EndFunc ;==>MessageBox Func Traitement_intermediaire() GUISetState(@SW_DISABLE, $g_hGUI1) gui2() ; display the listview ;.... EndFunc ;==>Traitement_intermediaire Func _Events_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $Msg, $wParam, $lParam) Local $tInfo, $Code $tInfo = DllStructCreate($tagNMHDR, $lParam) $hWnd = HWnd(DllStructGetData($tInfo, "hWndFrom")) $Code = DllStructGetData($tInfo, "Code") $hWnd_ListViewDatascope = GUICtrlGetHandle($hListViewDatascope) If $hWnd = $hWnd_ListViewDatascope Then Switch $Code Case $NM_DBLCLK ; Double-clic sur un élément de la ListView Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $iIndex = DllStructGetData($tInfo, "Index") ; indique le numero de ligne Local $iSubItem = DllStructGetData($tInfo, "SubItem") ;indique le numero de colonne Local $sText = _GUICtrlListView_GetItemText($hListViewDatascope, $iIndex, $iSubItem) $vRet = _GUIListViewEx_EventMonitor($iEditMode) MsgBox(0, "valeur click", "$iSubItem :" & $iSubItem & @CRLF & "$iIndex:" & $iIndex & @CRLF & "$sText:" & $sText & @CRLF & $vRet & @CRLF & "ret:&$ret") ;&@CRLF&"$hEdit:"&$hEdit) Case $NM_RCLICK ; right button Local $aSelected = _GUICtrlListView_GetSelectedIndices($hWnd, True) If $aSelected[0] > 0 Then MsgBox(0, "test", "Right Button") EndIf EndSwitch Return $GUI_RUNDEFMSG ; EndIf ; Must be LAST line of the handler Return (_GUIListViewEx_WM_NOTIFY_Handler($hWnd, $Msg, $wParam, $lParam)) EndFunc ;==>_Events_WM_NOTIFY
ermar Posted September 12 Author Posted September 12 Hi MattyD Exactly, thank you very much for your help. 🙂 I thought it was possible to include this “pause” in this second window like the _arraydisplay function. Is it too complicated to reproduce this functionality? Eric
Solution ioa747 Posted September 12 Solution Posted September 12 different approach, for 'exclusive mode' expandcollapse popup#AutoIt3Wrapper_UseX64=Y #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <MsgBoxConstants.au3> #include <Array.au3> #include <GuiMenu.au3> #include <GuiListView.au3> #include <EditConstants.au3> Opt("GUIOnEventMode", 1) Global $g_hGUI1, $g_hGUI2, $g_idButton1, $g_idButton2, $g_idButton3 Global $hListViewDatascope, $hDatabaseScope, $Button1, $Button2 ;a utiliser pour l'affichage de la 2eme fenetre Global $iEditMode = 0 gui1() Func gui1() $g_hGUI1 = GUICreate("GUI 1", 200, 200, 100, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") ; Call a common GUI close function $g_idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30) GUICtrlSetOnEvent(-1, "On_Button") ; Call a common button function $g_idButton2 = GUICtrlCreateButton("Show GUI 2", 10, 60, 80, 30) GUICtrlSetOnEvent(-1, "On_Button") ; Call a common button function $g_idButton3 = GUICtrlCreateButton("Traitement", 10, 100, 80, 30) GUICtrlSetOnEvent(-1, "Traitement_intermediaire") ; Call a traitement GUISetState() While 1 Sleep(10) WEnd EndFunc ;==>gui1 Func gui2() ; exclusive mode GUICtrlSetState($g_idButton2, $GUI_DISABLE) Opt("GUIOnEventMode", 0) ; when in $g_hGUI2 - disable <<<<<<<<<<<<<<< $g_hGUI2 = GUICreate("GUI 2", 500, 500) ;~ GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") ; Call a common GUI close function $g_idButton3 = GUICtrlCreateButton("GoOn", 10, 450, 100, 30) ;~ GUICtrlSetOnEvent(-1, "On_Button") ; Call a common button function $g_idButton4 = GUICtrlCreateButton("Cancel", 250, 450, 100, 30) ;~ GUICtrlSetOnEvent(-1, "On_Close") ; Call a common button function $hListViewDatascope = GUICtrlCreateListView("Tom|Dick|Harry", 10, 10, 400, 400, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetExtendedListViewStyle($hListViewDatascope, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) _GUICtrlListView_SetColumnWidth($hListViewDatascope, 0, 93) _GUICtrlListView_SetColumnWidth($hListViewDatascope, 1, 93) _GUICtrlListView_SetColumnWidth($hListViewDatascope, 2, 93) ; Set font GUICtrlSetFont($hListViewDatascope, 12, Default, Default, "Courier New") ; Note edit control will use same font ; Create array and fill listview Global $aLV_List[20] For $i = 0 To UBound($aLV_List) - 1 If Mod($i, 5) Then $aLV_List[$i] = "Tom " & $i & "|Dick " & $i & "|Harry " & $i Else $aLV_List[$i] = "Tom " & $i & "||Harry " & $i EndIf GUICtrlCreateListViewItem($aLV_List[$i], $hListViewDatascope) Next ;_GUIListViewEx_Init($hLV, $aArray = "", $iStart = 0, $iColour = 0, $fImage = False, $iAdded = 0) $iLVIndex_1 = _GUIListViewEx_Init($hListViewDatascope, $aLV_List, 0, 0, True, +1 + 4) ; Tri & modification possible ;_GUIListViewEx_SetEditStatus($iLV_Index, $vCol, $iMode = 1, $vParam1 = Default, $vParam2 = Default) _GUIListViewEx_SetEditStatus($iLVIndex_1, "1;2") ;modification des colonnes 1 & 2 _GUIListViewEx_SetActive($iLVIndex_1) ; Enregistrement des messages Windows _GUIListViewEx_MsgRegister(Default) GUIRegisterMsg($WM_NOTIFY, "_Events_WM_NOTIFY") GUISetState() Local $aMsg = 0 While 1 $aMsg = GUIGetMsg($GUI_EVENT_ARRAY) Switch $aMsg[1] ; Switch from GUIs Case $g_hGUI2 Switch $aMsg[0] ; Switch from event ID Case $GUI_EVENT_CLOSE, $g_idButton4 ConsoleWrite("GUI2: $GUI_EVENT_CLOSE=" & $GUI_EVENT_CLOSE & @CRLF) ExitLoop Case $g_idButton3 ConsoleWrite("GUI2: $g_idButton3=" & $g_idButton3 & @CRLF) MessageBox(2) EndSwitch EndSwitch WEnd GUIDelete($g_hGUI2) GUICtrlSetState($g_idButton2, $GUI_ENABLE) Opt("GUIOnEventMode", 1) ; when out of $g_hGUI2 - enable <<<<<<<<<<<<<<< EndFunc ;==>gui2 Func On_Close() Switch @GUI_WinHandle ; See which GUI sent the CLOSE message Case $g_hGUI1 Exit ; If it was this GUI - we exit <<<<<<<<<<<<<<< ;~ Case $g_hGUI2 ;~ GUIDelete($g_hGUI2) ; If it was this GUI - we just delete the GUI <<<<<<<<<<<<<<< EndSwitch EndFunc ;==>On_Close ;~ Func Off_Button() ;~ On_Close() ;~ EndFunc ;==>Off_Button Func On_Button() Switch @GUI_CtrlId ; See which button sent the message Case $g_idButton1 MessageBox(1) ; We can call a function with parameters here <<<<<<<<<<<<<<<<<<< Case $g_idButton2 gui2() ;~ Case $g_idButton3 ;~ MessageBox(2) ; We can call a function with parameters here <<<<<<<<<<<<<<<<<<< EndSwitch EndFunc ;==>On_Button Func MessageBox($iIndex) MsgBox($MB_OK, "MsgBox " & $iIndex, "Test from Gui " & $iIndex) EndFunc ;==>MessageBox Func Traitement_intermediaire() gui2() ; display the listview MsgBox(0, "Suite", "cela continue") ;suite du script ;.... EndFunc ;==>Traitement_intermediaire Func _Events_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $Msg, $wParam, $lParam) Local $tInfo, $Code $tInfo = DllStructCreate($tagNMHDR, $lParam) $hWnd = HWnd(DllStructGetData($tInfo, "hWndFrom")) $Code = DllStructGetData($tInfo, "Code") $hWnd_ListViewDatascope = GUICtrlGetHandle($hListViewDatascope) If $hWnd = $hWnd_ListViewDatascope Then Switch $Code Case $NM_DBLCLK ; Double-clic sur un 鬩ment de la ListView Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $iIndex = DllStructGetData($tInfo, "Index") ; indique le numero de ligne Local $iSubItem = DllStructGetData($tInfo, "SubItem") ;indique le numero de colonne Local $sText = _GUICtrlListView_GetItemText($hListViewDatascope, $iIndex, $iSubItem) $vRet = _GUIListViewEx_EventMonitor($iEditMode) MsgBox(0, "valeur click", "$iSubItem :" & $iSubItem & @CRLF & "$iIndex:" & $iIndex & @CRLF & "$sText:" & $sText & @CRLF & $vRet & @CRLF & "ret:&$ret") ;&@CRLF&"$hEdit:"&$hEdit) Case $NM_RCLICK ; right button Local $aSelected = _GUICtrlListView_GetSelectedIndices($hWnd, True) If $aSelected[0] > 0 Then MsgBox(0, "test", "Right Button") EndIf EndSwitch Return $GUI_RUNDEFMSG ; EndIf ; Must be LAST line of the handler Return (_GUIListViewEx_WM_NOTIFY_Handler($hWnd, $Msg, $wParam, $lParam)) EndFunc ;==>_Events_WM_NOTIFY pixelsearch 1 I know that I know nothing
MattyD Posted September 12 Posted September 12 No problems And yep, _ArrayDisplay() works the same way as ioa's example 👍 ioa747 1
ermar Posted September 13 Author Posted September 13 Thank you very much ioa747 , that's exactly what I was looking for 🙂 Have a great weekend, both of you. Reggards ioa747 and MattyD 2
ermar Posted October 15 Author Posted October 15 Hi all, I have a quick follow-up question about the previous example. In the second window : gui2() , there is a Cancel button. However, if I click Cancel in this gui2() while in Traitement_intermediaire () function, the processing still runs. How can the rest of the script be stopped completely? It works when I use Return on a single window, but not on this second window. Thank you for the help. Regards Eric
ioa747 Posted October 15 Posted October 15 I'm not sure I understand correctly Because in the example, while gui2 is open Traitement_intermediaire does not run, it remains frozen in gui2 and to continue, you have to close gui2 So Traitement_intermediaire does not run when gui2 is open I know that I know nothing
pixelsearch Posted October 16 Posted October 16 @ioa747 hello Maybe ermar asks for this : when he clicks on button "Traitement" in GUI1, then the function Traitement_intermediaire() is called, which calls gui2() and creates the listview. Now he starts to modify the listview, but suddenly he would like to cancel everything. Unfortunately, when he clicks the button "Cancel" in GUI2, the function Traitement_intermediaire() continues with this line in Traitement_intermediaire() MsgBox(0, "Suite", "cela continue") ;suite du script So we should indicate a way so the Cancel button in GUI2 reacts differently, depending on the part of the script which called gui2() 1) If gui2() was called from the function On_Button() => Case $g_idButton2 => gui2() , then no change is required 2) If gui2() was called from the function Traitement_intermediaire() => gui2() , then some code is required in case the user clicks on button Cancel in GUI2 . The change could be like this : Func Traitement_intermediaire() ; gui2() If gui2(1) Then Return MsgBox(0, "Suite", "cela continue") ;suite du script ;.... EndFunc ; Func gui2() Func gui2($iCancelStopsAll = 0) Local $iReturn = 0 ... Case $GUI_EVENT_CLOSE, $g_idButton4 If $iCancelStopsAll Then $iReturn = 1 ... Return $iReturn ; 0 or 1 EndFunc Note : if the GUI2 Close button [X] should react differently than the GUI2 Cancel button, then the Case should be splitted in 2 (one Case for $GUI_EVENT_CLOSE, another Case for $g_idButton4) Hope it makes sense... if this is what ermar asked for ! ermar and ioa747 2 "I think you are searching a bug where there is no bug... don't listen to bad advice."
ioa747 Posted October 16 Posted October 16 (edited) @pixelsearch thanks for the clarification, because I didn't think about/understand this case question, isn't that enough? Local $aMsg = 0, $iReturn = 0 While 1 $aMsg = GUIGetMsg($GUI_EVENT_ARRAY) Switch $aMsg[1] ; Switch from GUIs Case $g_hGUI2 Switch $aMsg[0] ; Switch from event ID Case $GUI_EVENT_CLOSE, $g_idButton4 ConsoleWrite("GUI2: $GUI_EVENT_CLOSE=" & $GUI_EVENT_CLOSE & @CRLF) If $aMsg[0] = $g_idButton4 Then ConsoleWrite(" with Cancel" & @CRLF) $iReturn = 1 EndIf ExitLoop Case $g_idButton3 ConsoleWrite("GUI2: $g_idButton3=" & $g_idButton3 & @CRLF) MessageBox(2) EndSwitch EndSwitch WEnd GUIDelete($g_hGUI2) GUICtrlSetState($g_idButton2, $GUI_ENABLE) Opt("GUIOnEventMode", 1) ; when out of $g_hGUI2 - enable <<<<<<<<<<<<<<< Return $iReturn EndFunc ;==>gui2 ... Func Traitement_intermediaire() ; display the listview If gui2() Then Return MsgBox(0, "Suite", "cela continue") ;suite du script ;.... EndFunc ;==>Traitement_intermediaire Edited October 16 by ioa747 ermar and pixelsearch 2 I know that I know nothing
pixelsearch Posted October 16 Posted October 16 42 minutes ago, ioa747 said: question, isn't that enough? Sure it's enough and better, no need of the optional parameter when calling gui2() Well done ! ioa747 and ermar 1 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
ermar Posted October 16 Author Posted October 16 Hi everyone, that's exactly right ! I found the solution at work this morning! But I couldn't respond. Like you, I considered adding a variable : $iRet_Value, but I tried to overcomplicate things at the beginning and i lost time ! Case $g_idButton4 ConsoleWrite("GUI2: CANCEL=" & $g_idButton4 & @CRLF) $iRet_Value ="KO" ExitLoop and i put : if $iRet_Value ="KO" then return instead : if gui2()... I didn't know this way : Func Traitement_intermediaire() ; display the listview If gui2() Then Return MsgBox(0, "Suite", "cela continue") ;suite du script ;.... EndFunc ;==>Traitement_intermediair Thank you for your help 🙂 pixelsearch and ioa747 2
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now