Jump to content

GuiCtrlCreateInput focus (typing) and enable radio button


ttleser
 Share

Recommended Posts

In the sample script below, I want to be able to have the $Radio_SearchEntireDrive radio button always disabled. However, I want to setup the script so that once someone begins typing in the $ComputerName input that the EntireDrive radio button gets enabled. Of course I want it disabled if the user deleted anything in the $ComputerName input.

The below script works, but only if I click off the $ComputerName field, which isn't what I'm looking. Anyone have any thoughts?

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
GUICreate("test",400,300)
GuiCtrlCreateLabel("UserName",10,10,110,20)
$UserName = GUICtrlCreateInput("",130,10,100,20)
GuiCtrlCreateLabel("ComputerName",10,50,110,20)
$ComputerName = GUICtrlCreateInput("",130,50,100,20)
$Radio_SearchProfileOnly = GUICtrlCreateRadio("User Profile Only?",250,10,100,20)
GUICtrlSetResizing(-1,$GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKSIZE)
GuiCtrlSetState(-1,$GUI_CHECKED)
$Radio_SearchEntireDrive = GUICtrlCreateRadio("Entire Drive?",250,50,100,20)
GuiCtrlSetState(-1,$GUI_DISABLE)
GUISetState(@SW_SHOW)
While 1
Sleep(50)
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE
   Exit
  Case $msg = $ComputerName
   GuiCtrlSetState($Radio_SearchEntireDrive,$GUI_ENABLE)
EndSelect
WEnd
Link to comment
Share on other sites

  • Moderators

ttleser,

Best way is to look for changes to the input content and then en/disable the radio like this: :)

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>


GUICreate("test", 400, 300)

GUICtrlCreateLabel("UserName", 10, 10, 110, 20)
$UserName = GUICtrlCreateInput("", 130, 10, 100, 20)
GUICtrlCreateLabel("ComputerName", 10, 50, 110, 20)
$ComputerName = GUICtrlCreateInput("", 130, 50, 100, 20)
$Radio_SearchProfileOnly = GUICtrlCreateRadio("User Profile Only?", 250, 10, 100, 20)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKSIZE)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio_SearchEntireDrive = GUICtrlCreateRadio("Entire Drive?", 250, 50, 100, 20)
GUICtrlSetState(-1, $GUI_DISABLE)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    ; Sleep(50) ; Not needed as there is a GUIGetMsg in the loop
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $ComputerName
            GUICtrlSetState($Radio_SearchEntireDrive, $GUI_ENABLE)
    EndSelect
WEnd

Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam)

    ; If it was an update message from the correct input
    If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $ComputerName Then
        If GUICtrlRead($ComputerName) = "" Then
            GUICtrlSetState($Radio_SearchEntireDrive, $GUI_DISABLE)
        Else
            GUICtrlSetState($Radio_SearchEntireDrive, $GUI_ENABLE)
        EndIf
    EndIf

EndFunc   ;==>_WM_COMMAND

If you are not used to GUIRegisterMsg, then I recommend the GUIRegisterMsg tutorial in the Wiki. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Give this Code a try, works fine.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
GUICreate("test",400,300)
GuiCtrlCreateLabel("UserName",10,10,110,20)
$UserName = GUICtrlCreateInput("",130,10,100,20)
GuiCtrlCreateLabel("ComputerName",10,50,110,20)
$ComputerName = GUICtrlCreateInput("",130,50,100,20)
$Radio_SearchProfileOnly = GUICtrlCreateRadio("User Profile Only?",250,10,100,20)
GUICtrlSetResizing(-1,$GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKSIZE)
GuiCtrlSetState(-1,$GUI_CHECKED)
$Radio_SearchEntireDrive = GUICtrlCreateRadio("Entire Drive?",250,50,100,20)
GuiCtrlSetState(-1,$GUI_DISABLE)
GUISetState(@SW_SHOW)
While 1
   Sleep(50)
   $msg = GUIGetMsg()
   Select
   Case $msg = $GUI_EVENT_CLOSE
   Exit
   Case $msg = $ComputerName
  
   EndSelect
   If GUICtrlRead($ComputerName) = "" then
   If GUICtrlGetState($Radio_SearchEntireDrive) <> 144 Then
   GuiCtrlSetState($Radio_SearchEntireDrive,$GUI_DISABLE)
   EndIf
   Else
   If GUICtrlGetState($Radio_SearchEntireDrive) <> 80 Then
   GuiCtrlSetState($Radio_SearchEntireDrive,$GUI_ENABLE)
   EndIf
   EndIf
   ;MsgBox(0,0,GUICtrlRead($ComputerName,1))
WEnd
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...