Jump to content

Recommended Posts

Posted

Hi All,


MAIN QUESTION:
Is it possible to Call specific function within a GUI


So I have a script with multiple functions although I don't want to use every function every time.
My Idea is to create a simple GUI which allows me to select what functions I want to use then run the funtions by clicking a button.

I have already made a GUI which allows me to select specific .exe's I would like to run after selection it runs the .exe one by one.
This script is on my work laptops and cannot access it right now.

 

Who can help me with this?

GUIcreate

Func1 
Func2
Func3

Then have a boxes which allows me to select the specif Func.(I used GUIChecked and Unchecked in my other script)
Then a button which executes/calls the selected functions

Posted (edited)

This is a quick modyfication for GUICreate() first Example from HelpFile :

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOK
                _ButtonOK_Pressed()
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

Func _ButtonOK_Pressed()
    MsgBox($MB_ICONINFORMATION, 'Info', 'Button OK Pressed')
EndFunc   ;==>_ButtonOK_Pressed

I this what you are looking for ?

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/21/2018 at 11:28 PM, mLipok said:

 

Expand  

Hi mLipok,

Thanks for you reply although I managed to find my script I mentioned above.

I modified it a bit:

This is my original script

#requireadmin
#include <GUIConstantsEx.au3>
#pragma compile(Icon, C:\Program Files (x86)\AutoIt3\Aut2Exe\Icons\AutoIt_Main_v10_48x48_256.ico)

$state = "UNCHECKED"
;CHECK BOXES
$gui=GUICreate("VidaXL App Installer", 500, 340)
;Standard Applications
$app1 = GUICtrlCreateCheckbox("7 Zip", 20, 30, 120, 20)
$app2 = GUICtrlCreateCheckbox("Google Chrome", 20, 50, 120, 20)



$standardSoftware = GUICtrlCreateLabel("Standard Software", 20, 10, 120, 20)
GUICtrlSetColor($StandardSoftware, 0x93117E)
GUICtrlSetFont($StandardSoftware,10,Default,Default,"Comic Sans MS")



$select=GUICtrlCreateButton("Select All", 20, 235, 100, 20)
$deselect=GUICtrlCreateButton("Deselect All", 20, 255, 100, 20)

$select2=GUICtrlCreateButton("Select All", 200, 235, 100, 20)
$deselect2=GUICtrlCreateButton("Deselect All", 200, 255, 100, 20)

$select3=GUICtrlCreateButton("Select All", 380, 235, 100, 20)
$deselect3=GUICtrlCreateButton("Deselect All", 380, 255, 100, 20)

$button=GUICtrlCreateButton("Start Installation", 150, 290, 200, 20)
$cancelbutton=GUICtrlCreateButton("Cancel", 150, 310, 200, 20)
$msg=GUISetState()

While 1

   Switch GUIGetMsg()
   Case $select
       GUICtrlSetState($app1, $GUI_CHECKED)
       GUICtrlSetState($app2, $GUI_CHECKED)
     
   Case $deselect
       GUICtrlSetState($app1, $GUI_UNCHECKED)
       GUICtrlSetState($app2, $GUI_UNCHECKED)


       Case $button
        If BitAnd(GUICtrlRead($app1),$GUI_CHECKED) = $GUI_CHECKED Then
           RunWait("\\sl051-file-01\IT Workstation\Software\Standard\7Zip.exe")
        EndIf
        If BitAnd(GUICtrlRead($app2),$GUI_CHECKED) = $GUI_CHECKED Then
           RunWait("\\sl051-file-01\IT Workstation\Software\Standard\Chrome.exe")
        EndIf
      


    Case $GUI_EVENT_CLOSE
       MsgBox(0, 'Thank you for using!', 'Made by Emmanuel Horvat')
        Exit
     Case $cancelbutton
        MsgBox(0, 'Thank you for using!', 'Made by Emmanuel Horvat')
        Exit
    EndSwitch
 WEnd

This works. As you see I get a GUI with 2 checkboxes. If I select app1 it only installs app1 if I select app1 and app2 it installs both and if I silect app2 it only installs app2

But like you see it uses runwait to run the EXE. In the new situation I have not created multiple exe's but more functions within the script

This is what I use now:

$app1 = GUICtrlCreateCheckbox("Char1", 20, 30, 120, 20)
$app2 = GUICtrlCreateCheckbox("Char2", 20, 50, 120, 20)
$select=GUICtrlCreateButton("Select All", 20, 235, 100, 20)
$deselect=GUICtrlCreateButton("Deselect All", 20, 255, 100, 20)

$button=GUICtrlCreateButton("Start Installation", 150, 290, 200, 20)
$cancelbutton=GUICtrlCreateButton("Cancel", 150, 310, 200, 20)
$msg=GUISetState()


While 1

   Switch GUIGetMsg()
   Case $select
       GUICtrlSetState($app1, $GUI_CHECKED)
       GUICtrlSetState($app2, $GUI_CHECKED)

   Case $deselect
       GUICtrlSetState($app1, $GUI_UNCHECKED)
       GUICtrlSetState($app2, $GUI_UNCHECKED)


   Case $button
        If BitAnd(GUICtrlRead($app1),$GUI_CHECKED) = $GUI_CHECKED Then
           Call("Char1")
        EndIf
        If BitAnd(GUICtrlRead($app2),$GUI_CHECKED) = $GUI_CHECKED Then
           Call("Char2")
        EndIf


    Case $GUI_EVENT_CLOSE
       MsgBox(0, 'Thank you for using!', 'Made by Emmanuel Horvat')
        Exit
     Case $cancelbutton
        MsgBox(0, 'Thank you for using!', 'Made by Emmanuel Horvat')
        Exit
    EndSwitch
 WEnd

Func Char1()
 WHAT THE FUNCTION DOESN BUT IT"S NOT IMPORTANT FOR NOW
EndFunc

Func Char2()

As you see it is the exact same but instead of runwait I use Call to select the function to run.

If I select Char1 it runs char1 function without issues

If I select char2 it runs char2 function without issues

If I select both it only runs char1

 

How do I make it to run the selected functions correctly.So if I select char1 and char2 that it runs both not only the first one.

Posted

You do not need to use Call() just change this:
 

If BitAnd(GUICtrlRead($app1),$GUI_CHECKED) = $GUI_CHECKED Then
           Call("Char1")
        EndIf
        If BitAnd(GUICtrlRead($app2),$GUI_CHECKED) = $GUI_CHECKED Then
           Call("Char2")
        EndIf

to:

If BitAnd(GUICtrlRead($app1),$GUI_CHECKED) = $GUI_CHECKED Then
           Char1()
        EndIf
        If BitAnd(GUICtrlRead($app2),$GUI_CHECKED) = $GUI_CHECKED Then
           Char2()
        EndIf

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Just using this simple example, both execute for me.

#include <GUIConstantsEx.au3>
#pragma compile(Icon, C:\Program Files (x86)\AutoIt3\Aut2Exe\Icons\AutoIt_Main_v10_48x48_256.ico)


;CHECK BOXES
$gui=GUICreate("VidaXL App Installer", 500, 340)
$app1 = GUICtrlCreateCheckbox("Char1", 20, 30, 120, 20)
$app2 = GUICtrlCreateCheckbox("Char2", 20, 50, 120, 20)
$select=GUICtrlCreateButton("Select All", 20, 235, 100, 20)
$deselect=GUICtrlCreateButton("Deselect All", 20, 255, 100, 20)

$button=GUICtrlCreateButton("Start Installation", 150, 290, 200, 20)
$cancelbutton=GUICtrlCreateButton("Cancel", 150, 310, 200, 20)
$msg=GUISetState()


While 1

   Switch GUIGetMsg()
   Case $select
       GUICtrlSetState($app1, $GUI_CHECKED)
       GUICtrlSetState($app2, $GUI_CHECKED)

   Case $deselect
       GUICtrlSetState($app1, $GUI_UNCHECKED)
       GUICtrlSetState($app2, $GUI_UNCHECKED)


   Case $button
        If BitAnd(GUICtrlRead($app1),$GUI_CHECKED) = $GUI_CHECKED Then
           Char1()
        EndIf
        If BitAnd(GUICtrlRead($app2),$GUI_CHECKED) = $GUI_CHECKED Then
           Char2()
        EndIf


    Case $GUI_EVENT_CLOSE
       MsgBox(0, 'Thank you for using!', 'Made by Emmanuel Horvat')
        Exit
     Case $cancelbutton
        MsgBox(0, 'Thank you for using!', 'Made by Emmanuel Horvat')
        Exit
    EndSwitch
 WEnd

Func Char1()
    msgbox(0,"","char1")
EndFunc

Func Char2()
    msgbox(0,"","char2")
EndFunc

Perhaps there is something else in your full script causing issue?

Posted

I found out yesterday I had no Case $button

I added it and now it seems to work but only for 1/2 functions again they don't run together

Posted

If you want to scale:

;#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Icon_Add=Resources\AddRemApp.ico
#AutoIt3Wrapper_Icon=Resources\AddRemApp.ico
#AutoIt3Wrapper_Run_Tidy=n
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WinAPI.au3>
#include <GuiEdit.au3>
#include <GuiButton.au3>
#include <Constants.au3>
#include <GuiStatusBar.au3>
#include <GUIConstants.au3>
#include <GuiImageList.au3>
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("TrayMenuMode", 1)
Opt("TrayIconHide", 1)
Opt("GUIResizeMode", 1)
Opt("TrayIconDebug", 1)
Opt("TrayAutoPause", 0)
Opt("MouseCoordMode", 2)
Opt("GUIOnEventMode", 0)
Opt("MustDeclareVars", 0)
Opt("GUIEventOptions", 1)
Opt("TrayOnEventMode", 1)
Opt("ExpandEnvStrings", 1)
Opt("WinDetectHiddenText", 1)

FileInstall("AutoIt Checkboxes Installation.au3", @ScriptDir & '\AutoIt Checkboxes Installation.au3', 1)

TraySetIcon("IMG\install2.ico")

Local $STR1 = StringInStr(@ScriptDir, '\', 2, 2)
Local $STR2 = StringLeft(@ScriptDir, $STR1)

$hGUI = GUICreate("AutoIt Install Menu", 740, 250, 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
$hlabel = GUICtrlCreateLabel("Select a Program to install", 30, 10, 126, 17)
$hButton1 = GUICtrlCreateButton("Start", 30, 200, 50)
$hButton2 = GUICtrlCreateButton("Select All", 80, 200, 80)
$hButton3 = GUICtrlCreateButton("UnSelect All", 160, 200, 80)

$totray = TrayCreateItem("Tray")
TrayItemSetOnEvent($totray, "ToTray")

$restore = TrayCreateItem("Restore")
TrayItemSetOnEvent($restore, "Restore")

$exititem = TrayCreateItem("Close")
TrayItemSetOnEvent($exititem, "Quit")

GUISetState()

Global $aRadio[32]
Global $aApps[32][3]
$aApps[0][0] = "W10Tools"
$aApps[0][1] = "W10Tools.exe"
$aApps[0][2] = "IMG\Pc.ico"
$aApps[1][0] = "SMP"
$aApps[1][1] = "AutoIt SMP.exe"
$aApps[1][2] = "IMG\SMP.ico"
$aApps[2][0] = "LAN"
$aApps[2][1] = "AutoIt LAN.exe"
$aApps[2][2] = "IMG\realtek.ico"
$aApps[3][0] = "Obsidian"
$aApps[3][1] = 'Obsidian\Obsidian.bat'
$aApps[3][2] = "Obsidian\normal.ico"
$aApps[4][0] = "Java"
$aApps[4][1] = "AutoIt Java.exe"
$aApps[4][2] = "IMG\java.ico"
$aApps[5][0] = "DX9c"
$aApps[5][1] = "AutoIt DX9c.exe"
$aApps[5][2] = "IMG\dx9c.ico"
$aApps[6][0] = "Create Synchronicity 6.0"
$aApps[6][1] = "Create Synchronicity 6.0.exe"
$aApps[6][2] = "IMG\sync.ico"
$aApps[7][0] = "Firefox"
$aApps[7][1] = "AutoIt FFox.exe"
$aApps[7][2] = "IMG\fox.ico"
$aApps[8][0] = "Group Policy Tool"
$aApps[8][1] = "GroupPolicy W10 X64\GPO Tool.exe"
$aApps[8][2] = "IMG\gpls.ico"
$aApps[9][0] = "Notepad ++"
$aApps[9][1] = "Notepad ++ 7.5.2 SFX.exe"
$aApps[9][2] = "IMG\notepad.ico"
$aApps[10][0] = "PowerCfgW10"
$aApps[10][1] = "PowerCfgW10.exe"
$aApps[10][2] = "IMG\power.ico"
$aApps[11][0] = "FlashPlayer"
$aApps[11][1] = "AutoIt FlashPlayer.exe"
$aApps[11][2] = "IMG\flashplayer.ico"
$aApps[12][0] = "WinRar"
$aApps[12][1] = "AutoIt WinRar.exe"
$aApps[12][2] = "IMG\winrar.ico"
$aApps[13][0] = "Foxit Reader"
$aApps[13][1] = "FoxitReaderPortable.exe"
$aApps[13][2] = "IMG\foxit.ico"
$aApps[14][0] = "Realtek R*"
$aApps[14][1] = "AutoIt RLTK x64.exe"
$aApps[14][2] = "IMG\realtek.ico"
$aApps[15][0] = "AutoIt + SciTE"
$aApps[15][1] = "AutoIt AutoIt + SciTe Silent.exe"
$aApps[15][2] = "IMG\autoit.ico"
$aApps[16][0] = "PhysX"
$aApps[16][1] = "AutoIt PhysX.exe"
$aApps[16][2] = "IMG\physx.ico"
$aApps[17][0] = "FM2 Chipset"
$aApps[17][1] = "F2A85M-LE\FM2_Chipset\Setup.exe"
$aApps[17][2] = "IMG\amd.ico"
$aApps[18][0] = "Logitech SetPoint"
$aApps[18][1] = "AutoIt Logitech SetPoint.exe"
$aApps[18][2] = "IMG\logitech.ico"
$aApps[19][0] = "Logitech GS"
$aApps[19][1] = "AutoIt LGS.exe"
$aApps[19][2] = "IMG\lgs.ico"
$aApps[20][0] = "Synaptics 17.0.19C"
$aApps[20][1] = "AutoIt Synaptics 17.0.19C.exe"
$aApps[20][2] = "IMG\synaptics.ico"
$aApps[21][0] = "Fraps"
$aApps[21][1] = "AutoIt Fraps.exe"
$aApps[21][2] = "IMG\fraps.ico"
$aApps[22][0] = "Reserved"
$aApps[22][1] = ""
$aApps[22][2] = "IMG\Blank.ico"
$aApps[23][0] = "Reserved"
$aApps[23][1] = ""
$aApps[23][2] = "IMG\Blank.ico"
$aApps[24][0] = "Reserved"
$aApps[24][1] = ""
$aApps[24][2] = "IMG\Blank.ico"
$aApps[25][0] = "Reserved"
$aApps[25][1] = ""
$aApps[25][2] = "IMG\Blank.ico"
$aApps[26][0] = "Reserved"
$aApps[26][1] = ""
$aApps[26][2] = "IMG\Blank.ico"
$aApps[27][0] = "Reserved"
$aApps[27][1] = ""
$aApps[27][2] = "IMG\Blank.ico"
$aApps[28][0] = "Reserved"
$aApps[28][1] = ""
$aApps[28][2] = "IMG\Blank.ico"
$aApps[29][0] = "Reserved"
$aApps[29][1] = ""
$aApps[29][2] = "IMG\Blank.ico"
$aApps[30][0] = "Reserved"
$aApps[30][1] = ""
$aApps[30][2] = "IMG\Blank.ico"
$aApps[31][0] = "Reserved"
$aApps[31][1] = ""
$aApps[31][2] = "IMG\Blank.ico"

For $i = 0 To 3
    For $j = 0 To 7
        $sName = ($aApps[($i * 8) + $j][0])
        GUICtrlCreateIcon($aApps[($i * 8) + $j][2], -2, 30 + ($i * 160), 30 + ($j * 20), 17, 17)
        $aRadio[($i * 8) + $j] = GUICtrlCreateCheckbox($sName, 50 + ($i * 160), 30 + ($j * 20), 138, 20)
    Next
Next

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton1
            For $i = 0 To 29
                If BitAND(GUICtrlRead($aRadio[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                    If Not FileExists($aApps[$i][1]) Then
                        MsgBox(262160, "File not found!", $aApps[$i][1], 0)
                    Else
                        ConsoleWrite("Running: " & $aApps[$i][0] & @CRLF)
                        ShellExecuteWait($aApps[$i][1])
                        TrayTip('Installer', "Running: " & $aApps[$i][0], 3)
                    EndIf
                EndIf
            Next
            ;================================================
        Case $hButton2 ;All
            For $i = 0 To 21
                GUICtrlSetState($aRadio[$i], $GUI_CHECKED)
            Next
            ;================================================
        Case $hButton3 ;None
            For $i = 0 To 31
                GUICtrlSetState($aRadio[$i], $GUI_UNCHECKED)
            Next
    EndSwitch
WEnd

Func ToTray()
    TrayItemSetState($totray, $TRAY_UNCHECKED)
    GUISetState(@SW_HIDE)
EndFunc   ;==>ToTray

Func Restore()
    TrayItemSetState($restore, $TRAY_UNCHECKED)
    GUISetState(@SW_SHOW)
EndFunc   ;==>Restore

Func Quit()
    Exit
EndFunc   ;==>Quit

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted (edited)

I managed to get it to work these are the changes

 

First

Func Char1()
 While 1
      Local $hWnd = WinWait($Class, "", 10)
      Local $iState = WinGetState($hWnd)

   If BitAND($Title, $WIN_STATE_EXISTS) Then
        WinActivate($Title)
    Else
        Exit
    EndIf

    Sleep(2000)

      Send("{q down}")
      Send("{q up}")

    Sleep(2000)
 WEnd
EndFunc

If I use this setup in both Functions only 1 is being executed

But if I change it to this it works:
 

Func Char1()
   WinActivate($Title)

    Sleep(5000)
    Send("{q down}")
      Send("{q up}")
EndFunc

 

The next problem is the functions itself. The functions contain a While this means it won't execute the second function because the first function is still in it's loop

 

Func Char1()

   While 1
      WinActivate($Title)
      Sleep(5000)
      Send("{q down}")
      Send("{q up}")
   WEnd 
EndFunc

Func Char2()
   While 1
      WinActivate($Title)
      Sleep(5000)
      Send("{a down}")
      Send("{a up}")
   WEnd
EndFunc

Is it possible to run the 2 functions at the same time?

 

EDIT: Managed to get it to work by not calling the function but by running a external script
The thing with this is I will have to create a lot of scripts imagine having 20 charactet this means 20 scripts atleast

If BitAnd(GUICtrlRead($Character1),$GUI_CHECKED) = $GUI_CHECKED Then
         $PID = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptDir & '\test.au3' & '"')

      EndIf
      If BitAnd(GUICtrlRead($Character2),$GUI_CHECKED) = $GUI_CHECKED Then
         $PID = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptDir & '\test1.au3' & '"')

 

Edited by Emmhor1
Posted

Run 2 functions at the same time would be multithreading so no.

But you could have it all in the main loop, set the conditions and it would run sequentially. And there's adlib.

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted
  On 10/22/2018 at 11:04 AM, careca said:

Run 2 functions at the same time would be multithreading so no.

But you could have it all in the main loop, set the conditions and it would run sequentially. And there's adlib.

Expand  

Could you set this up for me and then i Will expanderen it with my needs

Posted

I'll help you, and that's <> than doing it FOR you, besides it's easy enough so you can at least try.

A condition is for example:

If $varX = 1 Then

So if you put conditions, inside the main loop, and under these conditions, code to execute, this means you select what you want to get executed, just need to change the variables value. You can have for example checkboxes corresponding to what sections you want executed, the checkbox can be read, also in the main loop, and depending on checked or not, set the variable to 1 or 0. That simple.

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

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
×
×
  • Create New...