friends Posted October 31, 2004 Share Posted October 31, 2004 I'm stuck on how to toggle a button on (show) or off (hide) by pressing a same key ? Eg. F5 Anybody ? Link to comment Share on other sites More sharing options...
SlimShady Posted October 31, 2004 Share Posted October 31, 2004 Piece of cake. Here it is: expandcollapse popup#include <GUIConstants.au3> AutoItSetOption("TrayIconDebug", 1) ;Initialize variables Global $style1 Global $IniFile Global $GUIWidth Global $GUIHeight $GUIWidth = 250 $GUIHeight = 250 $IniFile = StringTrimRight(@ScriptFullPath, 3) & "ini" ;Only a close button: ;$style1 = BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU) ;GUICreate("New GUI", $GUIWidth, $GUIHeight, -1, -1, $style1) HotKeySet("{F5}", "SwapButton") GUICreate("Swap Button", $GUIWidth, $GUIHeight) $button_1 = GUICtrlCreateButton("OK", 50, 150, 70, 20) GUISetState(@SW_SHOW) While 1 Sleep(25) $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete() Exit EndSelect WEnd Func SwapButton() If NOT IsDeclared("ButtonState") Then Global $ButtonState = "On" If $ButtonState = "On" Then $ButtonState = "Off" GUICtrlSetState($button_1, $GUI_DISABLE) ElseIf $ButtonState = "Off" Then $ButtonState = "On" GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc Link to comment Share on other sites More sharing options...
friends Posted October 31, 2004 Author Share Posted October 31, 2004 (edited) SlimShady, thanks for prompt feedback. I know you're always being a helpful guy ! Edited October 31, 2004 by friends Link to comment Share on other sites More sharing options...
Developers Jos Posted October 31, 2004 Developers Share Posted October 31, 2004 (edited) Just as an alternative: You could test the current state to swap like: Func SwapButton() If GUICtrlGetState($button_1) = $GUI_ENABLE Then GUICtrlSetState($button_1, $GUI_DISABLE) Else GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc Edited October 31, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
friends Posted October 31, 2004 Author Share Posted October 31, 2004 Just as an alternative: You could test the current state to swap like:Func SwapButton() If GUICtrlGetState($button_1) = $GUI_ENABLE Then GUICtrlSetState($button_1, $GUI_DISABLE) Else GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc<{POST_SNAPBACK}>Thanks JdeB.... I will try it out. Link to comment Share on other sites More sharing options...
SlimShady Posted October 31, 2004 Share Posted October 31, 2004 Great idea JdeB. I tried it out and it didn't work so I tried to find out why. Here's a modified version that works: Func SwapButton() If GUICtrlGetState($button_1) = $GUI_ENABLE + $GUI_SHOW Then GUICtrlSetState($button_1, $GUI_DISABLE) Else GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc Link to comment Share on other sites More sharing options...
Developers Jos Posted October 31, 2004 Developers Share Posted October 31, 2004 (edited) Great idea JdeB.I tried it out and it didn't work so I tried to find out why.Here's a modified version that works:Func SwapButton() If GUICtrlGetState($button_1) = $GUI_ENABLE + $GUI_SHOW Then GUICtrlSetState($button_1, $GUI_DISABLE) Else GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc<{POST_SNAPBACK}>Yea... i didn't test it and didn't think of the other states it could have.This version should only test for ENABLED state only:Func SwapButton() If BitANd(GUICtrlGetState($button_1),$GUI_ENABLE) Then GUICtrlSetState($button_1, $GUI_DISABLE) Else GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc Edited October 31, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now