Jump to content

GUI Button -> update after being clicked


DarkBoost
 Share

Recommended Posts

Trying to update the button after being pressed.

Would I need to recall the AdlibEnable and if so how can I do this within the Loop?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Test GUI",180,50)
GUICtrlCreateLabel("Desktop -> data.txt",10,15)
$a=GUICtrlCreateButton("Delete",120,10)
GUICtrlSetState($a,$GUI_DISABLE)

GUISetState(@SW_SHOW)
AdlibEnable("Btn",200)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $a
            FileDelete(@DesktopDir&"\data.txt")
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch   
WEnd
        
Func Btn()
    If FileExists(@DesktopDir&"\data.txt") Then
        GUICtrlSetState($a,$GUI_ENABLE)
    Else
        GUISetState($a,$GUI_DISABLE)        
    EndIf
EndFunc
Link to comment
Share on other sites

I've never used Adlib, so i'm not sure this is what you're looking for:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Test GUI",180,50)
GUICtrlCreateLabel("Desktop -> data.txt",10,15)
$a=GUICtrlCreateButton("Delete",120,10)
GUICtrlSetState($a,$GUI_ENABLE)

GUISetState(@SW_SHOW)


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $a
            FileDelete(@DesktopDir&"\data.txt")
            GUICtrlSetState($a,$GUI_DISABLE)
            Sleep(1000) 
            If FileExists(@DesktopDir&"\data.txt") Then
            GUICtrlSetState($a,$GUI_ENABLE)
            Else
            GUISetState($a,$GUI_DISABLE)        
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
        EndSwitch
WEnd
Link to comment
Share on other sites

From what I understand the AdlibEnable is looping the Func throughout the script, however in my case it appears to stop looping after the button is pressed.

Your example is a manual process which is not updating realtime eg. whilst the script is running I manually create/delete the file and the button is not updating.

Link to comment
Share on other sites

What do you want to do? With something like just checking a file, you can shove it in the main message loop.

I'm still not 100% sure what you want to achieve...

Link to comment
Share on other sites

My apologizes, I will try my best to more clear and precise to avoid reader confusion.

1.) Create a simple GUI with a button named (delete) -> done

2.) Script button to delete a file on the desktop called (data.txt) when clicked -> done

3.) Enable/Disable the button if the file does/doesn't exist realtime eg. I start the script and then create the file, button should automatically update etc. -> need help!

I am attempting to use the AdlibEnable feature as advised in another thread however I am open to all suggestions.

Link to comment
Share on other sites

Look at your AdLib loop very closely... Spot the difference between mine and yours... :)

Func Btn()
    If FileExists(@DesktopDir&"\data.txt") Then
        GUICtrlSetState($a,$GUI_ENABLE)
    Else
        GUICtrlSetState($a,$GUI_DISABLE)        
    EndIf
EndFunc

Cheers,

Brett

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...