Jump to content

how to disable a button


newcoder
 Share

Recommended Posts

I would like to have a button grayed out until a certain condition is met;

The following doesn't show any button, so I assume its invisible;

$b1 = GUICtrlCreateButton("Button1",20,20,20,15,-1,@SW_DISABLE)

What is the correct extended style to disable and then re-enable a button?

Link to comment
Share on other sites

this is a part of a code I am currently working on...

#include <ButtonConstants.au3>
If $agi<2 Then
GUICtrlSetState($agid, $GUI_DISABLE)
ElseIf $agi>1 Then
GUICtrlSetState($agid, $GUI_ENABLE)
EndIf

The include might also be

#include <GUIConstantsEx.au3>

I have both in my code and I can't remember which one it is

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

GUICtrlCreateButton("Button1",20,20,20,15,-1) ;so you can see the button

GUICtrlSetState(-1,$GUI_DISABLE) ;this disables the button

GUICtrlSetState(-1,$GUI_ENABLE) ;this will enable the button

PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.
Link to comment
Share on other sites

@kaotkbliss I had <GUIConstantsEx.au3>, but not <buttonConstants.au3> - I added it but it did not help. I had also tried guictrlsetstate to set the state - for me it isn't changing anything.

@AppTux you have a variable your passing ($GUI_DISABLE) that I don't have, what is its value?

Thanks for the quick responses.

Link to comment
Share on other sites

@kaotkbliss I had <GUIConstantsEx.au3>, but not <buttonConstants.au3> - I added it but it did not help. I had also tried guictrlsetstate to set the state - for me it isn't changing anything.

Might help to see the code.

It might be that something else in the code is making the condition "true" when you believe it should be "false"

or since you were trying to use @SW_DISABLE then maybe you tried putting $GUI_DISABLE in it's place?

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Re-reading the posts I see your both showing $GUI_DISABLE instead of my @SW_DISABLE, which may be my problem. What is the value of $GUI_DISABLE?

I don't now what you're doing, but why do you not check in the helpfile and stop wasting our time here ;)
Link to comment
Share on other sites

$GUI_DISABLE is not available so I have @SW_DISABLE which may be my problem, but from what I saw in the extended style table I thought this was the correct choice. I also added several includes as I'm not sure which includes these variables yet. This snippet shows what I'm talking about - button1 is invisble and button2 is not disabled.

#Include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

Dim $b1, $b2, $bx, $hGUI
$hGUI = GUICreate("Test",200,200)
$b1 = GUICtrlCreateButton("Button1",20,25,50,15,-1,@SW_DISABLE)
$b2 = GUICtrlCreateButton("Button2",20,50)
$bx = GUICtrlCreateButton(" Exit ",20,100)
GUISetState()
GUICtrlSetState($b2,@SW_DISABLE)

While 1
    $msg = GUIGetMsg()
    Select
        case $msg = ""
        case $msg = $b1
            MsgBox(0,"","button 1")
        case $msg = $b2
            MsgBox(0,"","button 2")
        case $msg = $bx
            Exit
    EndSelect
WEnd
Link to comment
Share on other sites

try this!

#include <GUIConstantsEx.au3>



Dim $b1, $b2, $bx, $hGUI
$hGUI = GUICreate("Test",200,200)
$b1 = GUICtrlCreateButton("Button1",20,25,50,15)
GUICtrlSetState($b1,$GUI_DISABLE)
$c1=GUICtrlCreateButton("enable 1",70,25)
$b2 = GUICtrlCreateButton("Button2",20,50)
$c2=GUICtrlCreateButton("enable 2",70,50)
$bx = GUICtrlCreateButton(" Exit ",20,100)
GUISetState()
GUICtrlSetState($b2,$GUI_DISABLE)

While 1
    $msg = GUIGetMsg()
    Select
        case $msg = ""
        case $msg = $b1
            MsgBox(0,"","button 1")
        case $msg = $b2
            MsgBox(0,"","button 2")
        case $msg = $bx
            Exit
        Case $msg = $c1
        GUICtrlSetState($b1,$GUI_ENABLE)
        Case $msg = $c2
        GUICtrlSetState($b2,$GUI_ENABLE)
    EndSelect
WEnd

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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