Sign in to follow this  
Followers 0
JerichoJones

GUI - Exit Function when X is clicked?

8 posts in this topic

:D

The line in Bold/underline is where the problem lies.....

Below is the code (it should be self explanatory):

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

$main = GuiCreate("", 142, 110,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$bDisable = GuiCtrlCreateButton("Disable ScreenSaver", 10, 40, 120, 30)

$lScrWiz = GuiCtrlCreateLabel("ScreenSaver Wizard", 10, 10, 120, 20,$SS_SUNKEN + $SS_CENTER)

$lEnable = GuiCtrlCreateLabel("ScreenSaver Disabled!" & @CRLF & @CRLF & "Close the application to re-enable the screen saver.", 10, 35, 120, 80, + $SS_CENTER)

GUICtrlSetState($lEnable,$GUI_HIDE) ; the button is in hidden state

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUICtrlSetOnEvent($bDisable, "ScrDisable")

$regScrnSaver = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

GUISetState(@SW_SHOW)

While 1

Sleep(1000) ; Idle around

WEnd

Func ScrDisable()

$rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

If Not $rc = "" Then

Do

$rcd = RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

Sleep(1000)

Until $rcd = 1

EndIf

GUICtrlSetState($bDisable,$GUI_HIDE)

GUICtrlSetState($lEnable,$GUI_SHOW)

Do

$rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

If Not $rc = "" Then

RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

EndIf

Sleep("1000")

;MsgBox(0,"",GUICtrlGetState($main))

Until GUICtrlGetState($main) = $GUI_EVENT_CLOSE

EndFunc

Func CLOSEClicked()

RegWrite("HKCU\Control Panel\Desktop","SCRNSAVE.EXE","REG_SZ", $regScrnSaver)

Exit

EndFunc

Share this post


Link to post
Share on other sites



:D

The line in Bold/underline is where the problem lies.....

Below is the code (it should be self explanatory):

CODE
#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

$main = GuiCreate("", 142, 110,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$bDisable = GuiCtrlCreateButton("Disable ScreenSaver", 10, 40, 120, 30)

$lScrWiz = GuiCtrlCreateLabel("ScreenSaver Wizard", 10, 10, 120, 20,$SS_SUNKEN + $SS_CENTER)

$lEnable = GuiCtrlCreateLabel("ScreenSaver Disabled!" & @CRLF & @CRLF & "Close the application to re-enable the screen saver.", 10, 35, 120, 80, + $SS_CENTER)

GUICtrlSetState($lEnable,$GUI_HIDE) ; the button is in hidden state

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUICtrlSetOnEvent($bDisable, "ScrDisable")

$regScrnSaver = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

GUISetState(@SW_SHOW)

While 1

Sleep(1000) ; Idle around

WEnd

Func ScrDisable()

$rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

If Not $rc = "" Then

Do

$rcd = RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

Sleep(1000)

Until $rcd = 1

EndIf

GUICtrlSetState($bDisable,$GUI_HIDE)

GUICtrlSetState($lEnable,$GUI_SHOW)

Do

$rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

If Not $rc = "" Then

RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

EndIf

Sleep("1000")

;MsgBox(0,"",GUICtrlGetState($main))

Until GUICtrlGetState($main) = $GUI_EVENT_CLOSE

EndFunc

Func CLOSEClicked()

RegWrite("HKCU\Control Panel\Desktop","SCRNSAVE.EXE","REG_SZ", $regScrnSaver)

Exit

EndFunc

That Do/Unitl loop is unecesary. Just put it in a While 1 loop. Your Until condition never gets to end the Do loop because when $GUI_EVENT_CLOSE happens, the CLOSEClicked() function will exit the script first. So:

While 1
        $rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")
        If Not $rc = "" Then
            RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")
        EndIf
        Sleep("1000")
        ;MsgBox(0,"",GUICtrlGetState($main))
    Wend

:wacko:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

OK I have tried both suggestions yet when I click the X nothing happens. Minimize and maximize buttons work fine.

I am at a loss as to what to try next. :D

Share this post


Link to post
Share on other sites

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

$main = GUICreate("", 142, 110, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$bDisable = GUICtrlCreateButton("Disable ScreenSaver", 10, 40, 120, 30)
$lScrWiz = GUICtrlCreateLabel("ScreenSaver Wizard", 10, 10, 120, 20, $SS_SUNKEN + $SS_CENTER)
$lEnable = GUICtrlCreateLabel("ScreenSaver Disabled!" & @CRLF & @CRLF & "Close the application to re-enable the screen saver.", 10, 35, 120, 80, +$SS_CENTER)
GUICtrlSetState($lEnable, $GUI_HIDE) ; the button is in hidden state

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlSetOnEvent($bDisable, "ScrDisable")

$regScrnSaver = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")

GUISetState(@SW_SHOW)

While 1
    Sleep(1000) ; Idle around
WEnd

Func ScrDisable()
    $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")
    If Not $rc = "" Then
        $rcd = RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")
        Sleep(1000)
    EndIf
    
    GUICtrlSetState($bDisable, $GUI_HIDE)
    GUICtrlSetState($lEnable, $GUI_SHOW)
    
    $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")
    If Not $rc = "" Then
        RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")
    EndIf
    Sleep("1000")
EndFunc   ;==>ScrDisable

Func CLOSEClicked()
    RegWrite("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE", "REG_SZ", $regScrnSaver)
    Exit
EndFunc   ;==>CLOSEClicked


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Func ScrDisable()
    $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")
    If Not $rc = "" Then
        $rcd = RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")
        Sleep(1000)
    EndIf
    
    GUICtrlSetState($bDisable, $GUI_HIDE)
    GUICtrlSetState($lEnable, $GUI_SHOW)
    
    $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")
    If Not $rc = "" Then
        RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")
    EndIf
    Sleep("1000")
EndFunc   ;==>ScrDisable
OK. One thing I have determined is the If Not $rc = "" DOES NOT WORK. I had to change it to If $rc <> ""

I wanted a While or Do here to ensure that if the Screen Saver GPO gets re-applied that it is immediately deleted. How can I pull that off and have it still respond to the CloseClicked?

While 1

$rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")

If Not $rc = "" Then

RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")

EndIf

Sleep("1000")

WEnd

Thanks All!

jj

Share this post


Link to post
Share on other sites

Your code is evaluating Not operator before the = operater as Not has a higher precedence. So Not is evaluating $rc 1st, and then the result is evalutated with the = "". Use braces as shown below, to force Not to evaluate $rc = "" result. Operator Precedence shown in helpfile.

While 1
    $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")
    If Not ($rc = "") Then
        RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")
    EndIf
    Sleep("1000")
WEnd
oÝ÷ Ù8^"zËfzØhv+0«r¢ë!£"¶¬xØ-ýº)z¶­¢»¢êÂ
Xç^½éí².Û-Y_·*'íéh¢¢÷«zZqçr¢êì©e)¶ëaz趦N½ç±¶¶¢wb¶*'zö¥¹«b¢x§¶¥¢HÂ¥uÚ"¶Øb³²{-y§ZºÚ"µÍÚ[HBRYYÔXY
    ][ÝÒÐÕIÌLÐÛÛÛ[[    ÌLÑÚÝÜ ][ÝË  ][ÝÔÐÔÐUKVI][ÝÊH ÉÝÈ  ][ÝÉ][ÝÈ[BTYÑ[]J   ][ÝÒÐÕIÌLÐÛÛÛ[[    ÌLÑÚÝÜ ][ÝË  ][ÝÔÐÔÐUKVI][ÝÊBQ[YTÛY
    ][ÝÌL ][ÝÊBÑ[

:whistle:

Share this post


Link to post
Share on other sites

OK. Clicking X still does not respond nor does the value get deleted if it gets recreated. What am I doing wrong? :whistle:

Below is the updated code:

#NoTrayIcon

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

$main = GuiCreate("", 142, 110,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$bDisable = GuiCtrlCreateButton("Disable ScreenSaver", 10, 40, 120, 30)

$lScrWiz = GuiCtrlCreateLabel("ScreenSaver Wizard", 10, 10, 120, 20,$SS_SUNKEN + $SS_CENTER)

$lEnable = GuiCtrlCreateLabel("ScreenSaver Disabled!" & @CRLF & @CRLF & "Close this application to re-enable the screen saver.", 10, 35, 120, 80, + $SS_CENTER)

GUICtrlSetState($lEnable,$GUI_HIDE) ; the button is in hidden state

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUICtrlSetOnEvent($bDisable, "ScrDisable")

$regScrnSaver = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

GUISetState(@SW_SHOW)

While 1

Sleep(1000) ; Idle around

WEnd

Func ScrDisable()

$rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

If $rc <> "" Then

Do

$rcd = RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

;Sleep(1000)

$rca = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")

Until $rca = ""

EndIf

GUICtrlSetState($bDisable,$GUI_HIDE)

GUICtrlSetState($lEnable,$GUI_SHOW)

While 1

If RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") <> "" Then

RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE")

EndIf

Sleep("1000")

WEnd

EndFunc

Func CLOSEClicked()

RegWrite("HKCU\Control Panel\Desktop","SCRNSAVE.EXE","REG_SZ", $regScrnSaver)

Exit

EndFunc

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
Sign in to follow this  
Followers 0