Jump to content

Recommended Posts

Posted (edited)

Hi all,

how can I pause a GUI script in "OnEvent" mode?

If I make a loop my script will not responds until loop end...

Can't think another solution...

Plz help me

Regards,

Ozzy

Edited by Ozzy
Posted

Most event stuff would have a structure similar to this code snipet below

i.e.

1. globals

2. gui definition

3. call to init reoutine

4. a while loop (I think this is what you are missing)

5. functions executed for each event

#notrayicon
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

Global $oScriptlet 

$g_szVersion = "GUID Generator 1.0"
If WinExists($g_szVersion) Then 
    WinActivate ( $g_szVersion )
    Exit; It's already running
EndIf

$Form1 = GUICreate($g_szVersion, 257, 98, 193, 115, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Checkbox1 = GUICtrlCreateCheckbox("Always Send to Clipboard ", 8, 8, 153, 17)
GUICtrlSetOnEvent(-1, "ACheckbox1Click")
GUICtrlSetTip ( $Checkbox1, "Send all new GUID's to the clipboard.")

$AGUID = GUICtrlCreateInput("AGUID", 8, 32, 241, 21)
$AGenerate = GUICtrlCreateButton("Generate", 8, 64, 105, 25, 0)
GUICtrlSetOnEvent(-1, "AGenerateClick")
GUICtrlSetState($AGenerate ,$GUI_DEFBUTTON)
$AToClip = GUICtrlCreateButton("Send to Clipboard", 144, 64, 105, 25, 0)
GUICtrlSetOnEvent(-1, "AToClipClick")

GUISetOnEvent($GUI_EVENT_CLOSE,"OnExit")
GUISetState(@SW_SHOW)

 InitMe()

While 1
    Sleep(100)
WEnd
        
Func InitMe()
    $oScriptlet = ObjCreate ("Scriptlet.TypeLib")
    If @error = 1 Then
        MsgBox (0, "Error!", "Unable to create object")
        Exit
    Else
        GUICtrlSetState($Checkbox1,RegRead("HKCU\SOFTWARE\BOM\GUIDGEN","ClipKey"))
        AGenerateClick()
    EndIf
EndFunc
        
Func AGenerateClick()
    GUICtrlSetData($AGUID,GenerateGUID())
    If GUICtrlread($Checkbox1)  =  1 Then
        AToClipClick()
    EndIf
EndFunc
        
Func AToClipClick()
    ClipPut(GUICtrlRead($AGUID))
EndFunc

Func onExit()
    GUIDelete()
    Exit
EndFunc

Func ACheckbox1Click()
    RegWrite("HKCU\SOFTWARE\BOM\GUIDGEN", "ClipKey", "REG_SZ", GUICtrlread($Checkbox1))
EndFunc

Func GenerateGUID ()
    $oScriptlet = ObjCreate ("Scriptlet.TypeLib")
    Return $oScriptlet.Guid
EndFunc
Wallpaper Rotatorwith overlay, Loop through a folder of wallpaper & another of overlay, then create a combined image and set it as the wallpaperE-Mail passthru, Send any file, even executables via e-mail as plain text. The recipient can then later re-construct them.Slideshow widget, A slideshow widget similar to the Vista onePredictive typing using the Numpad, Predictive typing using the numpad of a keyboar similar to that on a mobile phone (the key is the .t16 file).PSTools Front End, For Remote Admin. Just makes life a lot easier (Demonstrates executing external programs and passing parameters, tabbed form Handling STDIN/STDERR)FTP Helper application Up and Download files from an FTP server demonstrates this and Tooltray TipsShow a Map of your Post-codes/Zip Codes, Uses the Clipboard, Hotkeys, the system tray (incl. menus)Disc/CD/DVD Catalogue, Ideal for all those Covermount Discs (Demonstrates Array handling, executing DOS programs, handling STDIN/STDOUT recursive directory reads, file searching.)YAST , Yet another Stopwatch/Timer (Uses a hotkey, Copies to clipboard, handles multiple events and stays on top)Keyboard Status Indicator , Indicates status of NumLock, Caps Lock and Scroll Lock Keys, demonstrates API calling & System tray Icon Toggling
Posted

Most event stuff would have a structure similar to this code snipet below

i.e.

1. globals

2. gui definition

3. call to init reoutine

4. a while loop (I think this is what you are missing)

5. functions executed for each event

#notrayicon
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

Global $oScriptlet 

$g_szVersion = "GUID Generator 1.0"
If WinExists($g_szVersion) Then 
    WinActivate ( $g_szVersion )
    Exit; It's already running
EndIf

$Form1 = GUICreate($g_szVersion, 257, 98, 193, 115, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Checkbox1 = GUICtrlCreateCheckbox("Always Send to Clipboard ", 8, 8, 153, 17)
GUICtrlSetOnEvent(-1, "ACheckbox1Click")
GUICtrlSetTip ( $Checkbox1, "Send all new GUID's to the clipboard.")

$AGUID = GUICtrlCreateInput("AGUID", 8, 32, 241, 21)
$AGenerate = GUICtrlCreateButton("Generate", 8, 64, 105, 25, 0)
GUICtrlSetOnEvent(-1, "AGenerateClick")
GUICtrlSetState($AGenerate ,$GUI_DEFBUTTON)
$AToClip = GUICtrlCreateButton("Send to Clipboard", 144, 64, 105, 25, 0)
GUICtrlSetOnEvent(-1, "AToClipClick")

GUISetOnEvent($GUI_EVENT_CLOSE,"OnExit")
GUISetState(@SW_SHOW)

 InitMe()

While 1
    Sleep(100)
WEnd
        
Func InitMe()
    $oScriptlet = ObjCreate ("Scriptlet.TypeLib")
    If @error = 1 Then
        MsgBox (0, "Error!", "Unable to create object")
        Exit
    Else
        GUICtrlSetState($Checkbox1,RegRead("HKCU\SOFTWARE\BOM\GUIDGEN","ClipKey"))
        AGenerateClick()
    EndIf
EndFunc
        
Func AGenerateClick()
    GUICtrlSetData($AGUID,GenerateGUID())
    If GUICtrlread($Checkbox1)  =  1 Then
        AToClipClick()
    EndIf
EndFunc
        
Func AToClipClick()
    ClipPut(GUICtrlRead($AGUID))
EndFunc

Func onExit()
    GUIDelete()
    Exit
EndFunc

Func ACheckbox1Click()
    RegWrite("HKCU\SOFTWARE\BOM\GUIDGEN", "ClipKey", "REG_SZ", GUICtrlread($Checkbox1))
EndFunc

Func GenerateGUID ()
    $oScriptlet = ObjCreate ("Scriptlet.TypeLib")
    Return $oScriptlet.Guid
EndFunc
I don't know what you mean with your code but I solved my issue...

I used an hibrid solution, simply turn off OnEvent mode while script is paused...

Here uncommented code:

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

Global $pause = False
Global $count = 0

$Form1 = GUICreate("Pause on event", 257, 98, 193, 115, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))

$lblCounter = GUICtrlCreateLabel("Counter:",10,10,80,15)

$btnPause = GUICtrlCreateButton("Pause", 8, 64, 105, 25, 0)
GUICtrlSetOnEvent($btnPause, "pause")
GUICtrlSetState($btnPause ,$GUI_DEFBUTTON)

$btnClose = GUICtrlCreateButton("Close", 120, 64, 105, 25, 0)
GUICtrlSetOnEvent($btnClose, "close")

GUISetState(@SW_SHOW)

While 1
    GUICtrlSetData($lblCounter,"Counter: "&$count)
    Sleep(500)
    $count += 1
WEnd

Func pause()
    Opt("GUIOnEventMode", 0)
    GUICtrlSetData($btnPause,"Resume")
    While 1
        $msg = GUIGetMsg()
        Select
         Case $msg = $GUI_EVENT_CLOSE
             close()
         Case $msg = $btnClose
             close()
         Case $msg = $btnPause
             ExitLoop
         EndSelect
         Sleep(200)
     WEnd
    Opt("GUIOnEventMode", 1)
EndFunc

Func close()
    If MsgBox(4,"Exit","Are you sure?")=6 Then
        Exit 0
    EndIf
EndFunc
Posted

I don't know what you mean with your code but I solved my issue...

I used an hibrid solution, simply turn off OnEvent mode while script is paused...

Here uncommented code:

have a look at this, it may help

an example

Wallpaper Rotatorwith overlay, Loop through a folder of wallpaper & another of overlay, then create a combined image and set it as the wallpaperE-Mail passthru, Send any file, even executables via e-mail as plain text. The recipient can then later re-construct them.Slideshow widget, A slideshow widget similar to the Vista onePredictive typing using the Numpad, Predictive typing using the numpad of a keyboar similar to that on a mobile phone (the key is the .t16 file).PSTools Front End, For Remote Admin. Just makes life a lot easier (Demonstrates executing external programs and passing parameters, tabbed form Handling STDIN/STDERR)FTP Helper application Up and Download files from an FTP server demonstrates this and Tooltray TipsShow a Map of your Post-codes/Zip Codes, Uses the Clipboard, Hotkeys, the system tray (incl. menus)Disc/CD/DVD Catalogue, Ideal for all those Covermount Discs (Demonstrates Array handling, executing DOS programs, handling STDIN/STDOUT recursive directory reads, file searching.)YAST , Yet another Stopwatch/Timer (Uses a hotkey, Copies to clipboard, handles multiple events and stays on top)Keyboard Status Indicator , Indicates status of NumLock, Caps Lock and Scroll Lock Keys, demonstrates API calling & System tray Icon Toggling

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