Jump to content

trouble activating the 2nd GUI (onEvent mode)


fastman
 Share

Recommended Posts

I am struggling with activating the 2nd GUI.  References of https://www.autoitscript.com/wiki/Managing_Multiple_GUIs did not help.

Gui2 and controls are created, but the buttons are not active.  I have tried to remove extra code.

Thanks for any help.

;
; cabinet maker process to automate MasterCam
;       ATP nesting process
;

#include <AutoItConstants.au3>
#include <Array.au3>
;#include <file.au3>
;#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPI.au3>
#include <WinAPIFiles.au3>
#include <WindowsConstants.au3>
;#include <XML.au3>; If XML library is updated, note that this script requires that save file will overwrite an existing file

Opt("GUIOnEventMode", 1) ; 1 = OnEvent mode

Opt("WinWaitDelay", 500) ; milliseconds
Opt("TrayIconDebug", 1)
Opt("WinSearchChildren", 1)

Global $hMainGUI
Global $hMainGUI2

Func GetAllWindowsControls($hCallersWindow, $bOnlyVisible = Default, $sStringIncludes = Default, $sClass = Default)
    If Not IsHWnd($hCallersWindow) Then
        ConsoleWrite("$hCallersWindow must be a handle...provided=[" & $hCallersWindow & "]" & @CRLF)
        Return False
    EndIf
    ; Get all list of controls
    If $bOnlyVisible = Default Then $bOnlyVisible = True
    If $sStringIncludes = Default Then $sStringIncludes = ""
    If $sClass = Default Then $sClass = ""
    $sClassList = WinGetClassList($hCallersWindow)

    ; Create array
    $aClassList = StringSplit($sClassList, @CRLF, 2)

    ; Sort array
    _ArraySort($aClassList)
    _ArrayDelete($aClassList, 0)

    ; Loop
    $iCurrentClass = ""
    $iCurrentCount = 1
    $iTotalCounter = 1

    If StringLen($sClass) > 0 Then
        For $i = UBound($aClassList) - 1 To 0 Step -1
            If $aClassList[$i] <> $sClass Then
                _ArrayDelete($aClassList, $i)
            EndIf
        Next
    EndIf

    For $i = 0 To UBound($aClassList) - 1
        If $aClassList[$i] = $iCurrentClass Then
            $iCurrentCount += 1
        Else
            $iCurrentClass = $aClassList[$i]
            $iCurrentCount = 1
        EndIf

        $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]")
        $text = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}")
        $aPos = ControlGetPos($hCallersWindow, "", $hControl)
        $sControlID = _WinAPI_GetDlgCtrlID($hControl)
        $bIsVisible = ControlCommand($hCallersWindow, "", $hControl, "IsVisible")
        If $bOnlyVisible And Not $bIsVisible Then
            $iTotalCounter += 1
            ContinueLoop
        EndIf

        If StringLen($sStringIncludes) > 0 Then
            If Not StringInStr($text, $sStringIncludes) Then
                $iTotalCounter += 1
                ContinueLoop
            EndIf
        EndIf

        If IsArray($aPos) Then
            ;ConsoleWrite("ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] IsVisible=[" & $bIsVisible & "] Text=[" & $text & "]." & @CRLF)
            ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] IsVisible=[" & $bIsVisible & "] Text=[" & $text & "]." & @CRLF)
        Else
            ;ConsoleWrite("ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF)
            ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF)
        EndIf

        If Not WinExists($hCallersWindow) Then ExitLoop
        $iTotalCounter += 1
    Next
    ;MsgBox($MB_SYSTEMMODAL, "title", "check console for control list")
EndFunc   ;==>GetAllWindowsControls

; ======= Func GetAllWindowsControls($hCallersWindow, $bOnlyVisible = Default, $sStringIncludes = Default, $sClass = Default) =========

Func setNestingOverlay()
    $ovrWidth = 400
    $ovrHeight = 60
    $ovrLeft = -1 ;$mcamWindow[0] + $nestControlRelative[0]
    $ovrTop = -1;$mcamWindow[1] + $nestControlRelative[1]+ 10

    $hMainGUI = GUICreate("covering mastercam buttons", $ovrWidth, $ovrHeight, $ovrLeft, $ovrTop, -1, $WS_EX_TOPMOST)

    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseButton2")

    Local $iOKButton1 = GUICtrlCreateButton("Continue to gui2", 20, 20, 80)
    GUICtrlSetOnEvent($iOKButton1, "NestResultButtonOverlay")

    GUISetState(@SW_SHOW, $hMainGUI)

    GetAllWindowsControls(WinGetHandle("[ACTIVE]"))

    ;loop to monitor button click
    While 1
        Sleep(50) ; Sleep to reduce CPU usage
    WEnd
    ConsoleWrite(" exit loop  setNestingOverlay")
EndFunc   ;==>setNestingOverlay


;=== 2nd gui ======= 2nd gui ======= 2nd gui ======= 2nd gui ======= 2nd gui ======= 2nd gui ====
func NestResultButtonOverlay()

    $ovrWidth = -1;$mcamWindow[2] - 10
    $ovrHeight = 70 ;40
    $ovrLeft = -1 ;$mcamWindow[0] + 5 ;+ $nestControlRelative[0]
    $ovrTop = -1 ;$mcamWindow[1] + $nestControlRelative[1]+ 10

    $hMainGUI2 = GUICreate("gui2-- covering nest result buttons", $ovrWidth, $ovrHeight, $ovrLeft, $ovrTop, -1, $WS_EX_TOPMOST)
    ;width, height, left, top

    ;GUISetState(@SW_DISABLE  + @SW_MINIMIZE, $hMainGUI)
    ;GUISwitch($hMainGUI2)

    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseButton2")

    local $iBackNestingButton = GUICtrlCreateButton("Back to Nesting", 20, 10, 120)
    GUICtrlSetOnEvent($iBackNestingButton, "backtoNesting")

    Local $iOKButton2 = GUICtrlCreateButton("Continue for g-Code", 160, 10, 120)
    GUICtrlSetOnEvent(-1, "generateGCode")
    ;GUICtrlSetOnEvent($iOKButton2, "generateGCode")

    Local $iDoneButton2 = GUICtrlCreateButton("Oops go back to vortex", 300, 10, 120)
    GUICtrlSetOnEvent($iDoneButton2, "CloseButton2")

    GUISetState(@SW_SHOW, $hMainGUI2)
    GUISetState(@SW_DISABLE  + @SW_MINIMIZE, $hMainGUI)
    GUISwitch($hMainGUI2)

    GetAllWindowsControls(WinGetHandle("[ACTIVE]"))

    While 1
        Sleep(50) ; Sleep to reduce CPU usage
    WEnd
        ConsoleWrite(" exit loop  NestResultButtonOverlay")
EndFunc   ;==>setNestingOverlay


func backtoNesting()
    msgbox($MB_SYSTEMMODAL, "gui2","backtoNesting")
EndFunc

Func CloseButton2()
    msgbox($MB_SYSTEMMODAL, "gui2","CloseButton2")
    Exit
EndFunc

func generateGCode()
    msgbox($MB_SYSTEMMODAL, "gui2","generateGCode")
EndFunc

; ===========   main ===========   main ===========   main ===========   main ===========   main ===========   main

setNestingOverlay()

 

Link to comment
Share on other sites

I see you have a while loop inside the func NestResultButtonOverlay. Why?

Remove the loop or the script becomes trapped there.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • Developers

The real issue here is that there can only be one event active at a given time, so when you click on the $iOKButton1 control in the Mainmenu, an Event is fired to show the second menu but the event doesn't end due to the While-Wend. So no other event can be activated from that point on.

Look at the Example in the Wiki https://www.autoitscript.com/wiki/Managing_Multiple_GUIs how it is done. :) 

Jos 

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

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...