Sign in to follow this  
Followers 0
kor

when returning to an input box, how to highlight the text?

9 posts in this topic

I would like the text highlighted if a user types an incorrect password. This way, they can simply begin typing a new password without having to press backspace to clear the input field.

Here is my code.

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

$domain = "test.local"

GUICreate(" Enter Credentials", 203, 100, @DesktopWidth / 2 - 160, -1, $WS_CAPTION) ; , $WS_CAPTION
GUICtrlCreateLabel("Enter your Active Directory credentials", 8, 4, -1, 25)
GUICtrlCreateLabel("Username:", 8, 28, 64, 20) ; username label ; left, top, width, height
$input1 = GUICtrlCreateInput("", 70, 25, 125, 20) ; username input
GUICtrlCreateLabel("Password:", 9, 52, 64, 20) ; password label
$input2 = GUICtrlCreateInput("", 70, 49, 125, 20, $ES_PASSWORD)
$ok = GUICtrlCreateButton("&OK", -1, 75, 60, 20)
GUICtrlSetState($ok, 512) ; allows enter inside input boxes
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Local $user = GUICtrlRead($input1)
    Local $pass = StringReplace(GUICtrlRead($input2), "ad\", "") ;removes leading ad\ 
    Select
        Case $msg = $ok
            ; this code will attempt to map a drive using credentials provided above
            ; if drive map is successfull it is assumed the username and password combo are good and continues
            If $user <> "" And $pass <> "" Then
                $strQueryDom = "netdom query /domain:" & $domain & " /userD:" & $user & " /passwordD:" & $pass & " dc"
                $strQueryDomResult = RunWait(@Comspec & " /C" & $strQueryDom,'',@SW_HIDE)
                If $strQueryDomResult <> 0 Then
                    MsgBox (16, "Error", "Password is incorrect")
                    GUICtrlSetState($pass, 256)
                Else
                    $Status = 1
                    ExitLoop
                EndIf
            Else
                Select
                    Case $user = "" And $pass = ""
                        MsgBox(16, "Error", "Username cannot be blank")
                    Case $pass = ""
                        MsgBox(16, "Error", "Password cannot be blank")
                        GUICtrlSetState($pass, 256)
                    Case $user = ""
                        MsgBox(16, "Error", "Username cannot be blank")
                        GUICtrlSetState($user, 256)
                EndSelect
            EndIf
        ;Case Else
        ;   Sleep(2000)
    EndSelect
WEnd

Share this post


Link to post
Share on other sites



GuiCtrlSetState($My_Input, $GUI_FOCUS)


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

Share this post


Link to post
Share on other sites

Awesome, I took the gui code from another example on the forum. After looking it looks like the persons code sets the gui flag as a value (256) in this instance. I wasn't sure what that did exactly.

Share this post


Link to post
Share on other sites

256 is the value of $GUI_FOCUS


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

Share this post


Link to post
Share on other sites

is there anywhere in the help file that compares the different flags to their value? I couldn't find anything that ties the two together.

Share this post


Link to post
Share on other sites

The Constants values are in the constants files in your Program Files\AutoIt3\Include folder. In this case it is in the GUIConstantsEx.au3 file.


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

Share this post


Link to post
Share on other sites

And if you use SciTE4AutoIt you can also use Alt+I to open the Include File in SciTE. Make sure you cursor selects the Include line e.g. #include <Array.au3> and then hit the HotKey Alt+I


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Any suggestions to my code? Because I am already setting value 256 which is gui focus on the password input if the password in incorrect. However the GUI is not highlighting the password, it's only just going back to the box with the cursor at the end of the password.

I am trying to get it to return back to the password box with the entire password highlighted, so if a user begins typing it replaces the current password.

Share this post


Link to post
Share on other sites

You were making the common mistake of using the value of the control rather than the control IDs $input2 and $input2 when setting the focus to the control. I've also added a line to set the contents of the password control to "" when the value is incorrect to save the user having to clear it themselves. It is little things like that that make a GUI a pleasure to use or just plain annoying.

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

$domain = "test.local"

GUICreate(" Enter Credentials", 203, 100, @DesktopWidth / 2 - 160, -1, $WS_CAPTION) ; , $WS_CAPTION
GUICtrlCreateLabel("Enter your Active Directory credentials", 8, 4, -1, 25)
GUICtrlCreateLabel("Username:", 8, 28, 64, 20) ; username label ; left, top, width, height
$input1 = GUICtrlCreateInput("", 70, 25, 125, 20) ; username input
GUICtrlCreateLabel("Password:", 9, 52, 64, 20) ; password label
$input2 = GUICtrlCreateInput("", 70, 49, 125, 20, $ES_PASSWORD)
$ok = GUICtrlCreateButton("&OK", -1, 75, 60, 20)
GUICtrlSetState($ok, 512) ; allows enter inside input boxes
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Local $user = GUICtrlRead($input1)
    Local $pass = StringReplace(GUICtrlRead($input2), "ad\", "") ;removes leading ad\
    Select
        Case $msg = $ok
            ; this code will attempt to map a drive using credentials provided above
            ; if drive map is successfull it is assumed the username and password combo are good and continues
            If $user <> "" And $pass <> "" Then
                $strQueryDom = "netdom query /domain:" & $domain & " /userD:" & $user & " /passwordD:" & $pass & " dc"
                $strQueryDomResult = RunWait(@Comspec & " /C" & $strQueryDom,'',@SW_HIDE)
                If $strQueryDomResult <> 0 Then
                    MsgBox (16, "Error", "Password is incorrect")
                    GUICtrlSetData($input2, "") ;<<<<<<<<========= Clear the invlaid password ready for the user to retry
                    GUICtrlSetState($input2, 256) ;<<<<<<<<======= Set focus to the password box
                Else
                    $Status = 1
                    ExitLoop
                EndIf
            Else
                Select
                    Case $user = "" And $pass = ""
                        MsgBox(16, "Error", "Username cannot be blank")
                        GUICtrlSetState($input1, 256) ;<<<<<<<<======= Set focus to the user box
                    Case $pass = ""
                        MsgBox(16, "Error", "Password cannot be blank") ;<<<<<<<<======= Set focus to the password box
                        GUICtrlSetState($input2, 256)
                    Case $user = ""
                        MsgBox(16, "Error", "Username cannot be blank") ;<<<<<<<<======= Set focus to the user box
                        GUICtrlSetState($input1, 256)
                EndSelect
            EndIf
        ;Case Else
        ;   Sleep(2000)
    EndSelect
WEnd

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
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
Sign in to follow this  
Followers 0