Jump to content

Displaying a new GUI (listview) in a traitment - (Moved)


Go to solution Solved by ioa747,

Recommended Posts

Posted

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
Posted

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.
  :)

Posted

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??

#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

 

Posted

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
Posted

different approach, for 'exclusive mode'

#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

 

I know that I know nothing

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...