gseller Posted March 5, 2008 Posted March 5, 2008 I am trying to setup a gui with at least one input and a button. Example: a search input with a disabled search button until the input is selected. I have this so far but does not enable when focus is on the input. Any help or ideas would be greatly apreciated.. Also the button flickers terribly when mouse is moved. #include <GUIConstants.au3> $hGui = GUICreate("Button Disabled Until Input Focus Example", 350, 75, 193, 125) $Input1 = GUICtrlCreateInput("", 16, 16, 233, 21) $Input2 = GUICtrlCreateInput("", 16, 40, 233, 21) GUICtrlSetState(-1,$GUI_FOCUS) $Button1 = GUICtrlCreateButton("Button1", 256, 16, 75, 25) GUISetState(@SW_SHOW) While 1 If $Input1 > 0 Then GUICtrlSetState($Button1, $GUI_DISABLE) Else GUICtrlSetState($Button1, $GUI_ENABLE) EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
Uriziel01 Posted March 5, 2008 Posted March 5, 2008 Something like this ?? #include <GUIConstants.au3> $hGui = GUICreate("Button Disabled Until Input Focus Example", 350, 75, 193, 125) $Input1 = GUICtrlCreateInput("", 16, 16, 233, 21) $Input2 = GUICtrlCreateInput("", 16, 40, 233, 21) GUICtrlSetState(-1,$GUI_FOCUS) $Button1 = GUICtrlCreateButton("Button1", 256, 16, 75, 25) GUISetState(@SW_SHOW) $i=1 While 1 If GUICtrlRead($Input1) = "" and $i=1 Then GUICtrlSetState($Button1, $GUI_DISABLE) $i=0 Else if $i=0 and GUICtrlRead($Input1) <> "" then GUICtrlSetState($Button1, $GUI_ENABLE) $i=1 endif EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
gseller Posted March 5, 2008 Author Posted March 5, 2008 Cool!! I was looking for it to enable when clicked on the input but this will do very nicely.. Thank You So Much!!
Uriziel01 Posted March 5, 2008 Posted March 5, 2008 No problem Im glad that my code was helpful for You
GEOSoft Posted March 5, 2008 Posted March 5, 2008 Cool!! I was looking for it to enable when clicked on the input but this will do very nicely.. Thank You So Much!!You might want to change that code a wee bit. If GUICtrlRead($Input1) = "" Then If GUICtrlGetState($Button1) = 80 Then GUICtrlSetState($Button1, 144) Else If GUICtrlGetState($Button1) > 80 Then GUICtrlSetState($Button1, 80) Endif It's best to check a state before setting one to avoid flicker. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Uriziel01 Posted March 5, 2008 Posted March 5, 2008 I have already added the $i variable to avoid flickering. But In fact your solution is shorter than my, thank for sharing
rasim Posted March 6, 2008 Posted March 6, 2008 Hi gessler!Try this:expandcollapse popup#include <GUIConstants.au3> $hGui = GUICreate("Button Disabled Until Input Focus Example", 350, 75, 193, 125) $Input1 = GUICtrlCreateInput("", 16, 16, 233, 21) $Input2 = GUICtrlCreateInput("", 16, 40, 233, 21) GUICtrlSetState(-1,$GUI_FOCUS) $Button1 = GUICtrlCreateButton("Button1", 256, 16, 75, 25) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $IdFrom, $iCode $IdFrom = BitAnd($wParam, 0x0000FFFF) $iCode = BitShift($wParam, 16) Switch $IdFrom Case $Input1 Switch $iCode Case $EN_SETFOCUS GUICtrlSetState($Button1, $GUI_DISABLE) Case $EN_KILLFOCUS GUICtrlSetState($Button1, $GUI_ENABLE) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc
gseller Posted March 6, 2008 Author Posted March 6, 2008 That is cool too! It does the enable/disable on focus but seems kinda buggy for me. the second input has to be clicked in order to disable the button. I like it tho..
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