Jump to content

Disable Button until focus on GUICtrlCreateInput


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!"

Link to comment
Share on other sites

Hi gessler!

Try 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)

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