Jump to content
fastman

trouble activating the 2nd GUI (onEvent mode)

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()

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks - that works.

The loop was added so the script does not end but waits for button press. 

To clarify my understanding: 

  •  the script only needs the loop for the first GUI, 
  • any following GUI needs no loop.

Share this post


Link to post
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

  • Similar Content

    • By jpomalley
      Hi all,
      Does anyone know if there is a way to disable the Windows "fade effect" that occurs when a window appears or disappears?
      It is possible for a user to disable visual effects in windows in general through the system properties > performance settings, but I am interested just in fixing it for a particular window that pops up in my app.
      I would like it to appear and disappear instantaneously, snapping in and out, out of nowhere, rather than the short (maybe 300 ms?) fade in/fade out effect that windows has.
      Thanks for any tips
      JP
    • By Blueman
      Hey Guys,
      Maybe you can help me with something small.
      It is not terrible but it slows down my script and after a while even crash the script.

      First i explain what i have;
      I have a GUI with a lot of GUICtrlCreateInput controls, lets say 600 pieces.
      All the controls are hidden when the GUI is displayed, i have 3 buttons attached to 200 pieces each.
      When i press button-1 the first 200 controls are showed,
      When i press button-2 the first 200 controls are hidden and the next 200 controls are showed,
      etc, etc.
      This is working perfectly but after a while the GUI is getting slower and slower.
      After a while the controls aren't responding anymore and the script crashes.
      When i compile the script to 64-Bits version the speed is a lot better but you can still see the script slowing down each time i use the buttons.
      I think there has to be a buffer somewhere that is filling each time i show and hide the controls, but how can i clear that buffer without restarting the script?
      Deleting and re-creating the controls didn't help, deleting the entire gui (and controls) and re-creating it didn't help also.
      The only thing that is working is restarting the script.

      Thanks guys!

      PS: If you need a working example i can add it to this topic, just let me know. It is not rocket science, i just create the controls and show/hide them with a while loop and 3 buttons.
       
    • By TheDcoder
      ProxAllium
      ProxAllium is a GUI frontend to Tor, it aims to make the usage of Tor easier by directly exposing its SOCK5 proxy which can be used to access the Tor network. The GUI is designed to be simple and user-friendly and it has a few other features... namely:
      Fully portable - doesn't write outside its own directory Integrated with Tor via the controller interface and properly communicates with it Minimize to tray Option to start with Windows Interface to configure bridges if Tor is censored in your region Many customization options are available via the config.ini file Screenshots:
      The code is made with pure AutoIt, is fully open source and you are free to adapt it to your needs
      The GitHub repository hosts all the releases and code. As a bonus it has a somewhat sparsely documented Tor UDF which can be used to control Tor, the code also demonstrates the proper usage of my Process UDF which might be interesting if you want to deal with processes.
       
      As some of my friends know, I no longer use Windows as my main operating system. I switched to Linux a few months back as my primary operating system and haven't looked back since. Unfortunately that meant I could no longer use my own program due to it being Windows only... after a few months of playing around with C and making a basic program, I have decided to rewrite all of ProxAllium into C and make it cross-platform. Sadly this means that the AutoIt version of ProxAllium will not receive any major updates now.
      Let me know if this is something you guys would use, I used it daily with my IRC client to connect via Tor (to protect my I.P). I hope you enjoy using my program!
    • By morion84
      Hi, when I call a MsgBox function I can use a "$MB_SERVICE_NOTIFICATION" flag so it will be displayed "on the current active desktop, even if there is no user logged on to the computer.". That works just great. Is there a way to do the same to Autoit GUI Form so it will be visible on desktop even if running from system account and user is not logged?
    • By remin
      I do have one autoit script file with multiple functions.
      p.e.
       
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <String.au3> #include <GuiButton.au3> #include <Constants.au3> #include <EditConstants.au3> #include <Misc.au3> #include <MsgBoxConstants.au3> #include <HotString.au3> Func ACase() $Form4=GUICreate("ACase", 100, 195, 290, 142) etc etc GUISetState(@SW_SHOW, $Form4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE SUB_Write2ini(....) ;I write a few things in an ini file Case $a Case $b etc EndSwitch WEnd EndFunc Func BCase() $Form5=GUICreate("BCase", 100, 195, 290, 142) etc etc GUISetState(@SW_SHOW, $Form5) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE SUB_Write2ini(....) ;I write a few things in an ini file Case $a Case $b etc EndSwitch WEnd EndFunc When I activate the 1st function (ACase), using a shortcut and the 2nd function (BCase) (with a different shortcut) and I click on a button in whatever of these 2 Gui's, I can't use the other Gui anymore. It doesn't do the right thing as if autoit only remembers the Gui I first used.
      What did I wrong? How can I let autoit know which GUI is active and to connect to the function of that Gui?
      Hope I made myself clear.
       
×
×
  • Create New...