Jump to content

Password Input Mini-UDF


smartee
 Share

Recommended Posts

Here is a UDF consisting of just three functions that make it extremely simple to manipulate Input controls with the $ES_PASSWORD style.

Inspired by

Technical overview:

Works by sending a couple messages to the Input control then redrawing it.

Features:

  • A pseudo Password Input control for simplicity and visually descriptive code
  • Simple integration with Checkbox controls so creating the cliche "Show password" Checkbox will be a breeze
  • A _GUICtrlPasswordDisplay() function to show or hide the characters of a Password Input control
Change-log:

  • 29/06/2011: Version 1.4

    • Updated _GUICtrlPasswordDisplay function (thanks ProgAndy) and all functions relying on it (script-breaking)
    • Updated examples, API, userudfs properties and help-file :huh2:
  • 28/06/2011: Version 1.3

    • Fixed bug that caused the whole window to be redrawn.
    • Simplified examples.
    • Fixed UDF layout.
    • Added call-tips API and userudfs properties to zip.
    • Added "GUIPassword.chm" help-file to zip.
Screenshots:

Demo 1 (_GUICtrlCreatePassword.au3)

Posted Image

Code:

Demo 1 (_GUICtrlCreatePassword.au3):

#include <GUIPassword.au3>

$Form1 = GUICreate("_GUICtrlCreatePassword Example", 300, 51)
$Password1 = _GUICtrlCreatePassword("Password1", 5, 5, 290, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Show password", 5, 31, 100, 15)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            _GUICtrlPasswordCheckbox($Password1, $Checkbox1)
    EndSwitch
WEnd

Demo 2 (_GUICtrlPasswordDisplay.au3):

#include <GUIPassword.au3>

$Form1 = GUICreate("_GUICtrlPasswordDisplay Example", 374, 171)
$Tab1 = GUICtrlCreateTab(12, 12, 349, 97)
$TabSheet1 = GUICtrlCreateTabItem("Passform1")
$Password1 = _GUICtrlCreatePassword("Password1", 28, 49, 313, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Show password", 28, 73, 169, 25)
$TabSheet2 = GUICtrlCreateTabItem("Passform2")
$Checkbox2 = GUICtrlCreateCheckbox("Show passwords 2 and 3", 28, 73, 169, 25)
$Password2 = _GUICtrlCreatePassword("Password2", 28, 49, 313, 21)
GUICtrlCreateTabItem("")
$Label1 = GUICtrlCreateLabel("Show password 1 from Passform1", 12, 144, 169, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$Password3 = _GUICtrlCreatePassword("Password3", 12, 120, 349, 21)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            _GUICtrlPasswordCheckbox($Password1, $Checkbox1)
        Case $Checkbox2
            _GUICtrlPasswordCheckbox($Password2, $Checkbox2)
            _GUICtrlPasswordCheckbox($Password3, $Checkbox2)
        Case $Label1
            _GUICtrlPasswordDisplay($Password1)
            GUICtrlSetState($Checkbox1, $GUI_CHECKED)
    EndSwitch
WEnd

And the UDF itself (GUIPassword.au3):

#AutoIt3Wrapper_AU3Check_Parameters=-d -w1 -w2 -w3 -w4 -w5 -w6
#include-once
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

; #INDEX# =======================================================================================================================
; Title .........: GUI Password version 1.4
; AutoIt Version : 3.3 +
; Language ......: English
; Description ...: Tiny UDF to make Input controls with the $ES_PASSWORD style easy to manipulate.
; Author(s) .....: smartee, ProgAndy
; Dll(s) ........: user32.dll
; ===============================================================================================================================

; #VARIABLES# ===================================================================================================================
Global $__DEF_PASS_CHAR = -1
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
;_GUICtrlCreatePassword
;_GUICtrlPasswordCheckbox
;_GUICtrlPasswordDisplay
;================================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlCreatePassword
; Description ...: Creates a Input control with the $ES_PASSWORD style.
; Syntax.........: _GUICtrlCreatePassword($sText, $iLeft, $iTop, $iWidth, $iHeight [, $iStyle = -1 [, $iExStyle = -1]])
; Parameters ....: $sText    - The text of the control.
;                  $iLeft    - The left side of the control. If -1 is used then left will be computed according to GUICoordMode.
;                  $iTop     - The top of the control. If -1 is used then top will be computed according to GUICoordMode.
;                  $iWidth   - The width of the control (default is the previously used width).
;                  $iHeight  - The height of the control (default is the previously used height).
;                  $iStyle   - [optional] Defines the style of the control. See GUI Control Styles Appendix.
;                  $iExStyle - [optional] Defines the extended style of the control. See Extended Style Table.
; Return values .: Success - Returns the identifier (controlID) of the new control.
;                  Failure - Returns 0.
; Author ........: smartee
; Modified.......:
; Remarks .......:
; Related .......: _GUICtrlPasswordCheckbox, _GUICtrlPasswordDisplay
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _GUICtrlCreatePassword($sText, $iLeft, $iTop, $iWidth, $iHeight, $iStyle = -1, $iExStyle = -1)
    If $iStyle = -1 Then $iStyle = BitOR($ES_PASSWORD, $ES_AUTOHSCROLL)
    Local $Password1 = GUICtrlCreateInput($sText, $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle)
    If $__DEF_PASS_CHAR = -1 Then $__DEF_PASS_CHAR = GUICtrlSendMsg($Password1, $EM_GETPASSWORDCHAR, 0, 0)
    Return $Password1
EndFunc   ;==>_GUICtrlCreatePassword

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPasswordCheckbox
; Description ...: Links the password display function to the state of a checkbox.
; Syntax.........: _GUICtrlPasswordCheckbox($iPasswordID, $iCheckboxID)
; Parameters ....: $iPasswordID - The control identifier (controlID) of the input control as returned by
;                  +_GUICtrlCreatePassword or GUICtrlCreateInput.
;                  $iCheckboxID - The control identifier (controlID) of the checkbox control as returned by
;                  +GUICtrlCreateCheckbox.
; Return values .: Success      - True
;                  Failure      - False
; Author ........: smartee
; Modified.......:
; Remarks .......:
; Related .......: _GUICtrlCreatePassword, _GUICtrlPasswordDisplay
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _GUICtrlPasswordCheckbox($iPasswordID, $iCheckboxID)
    If (GUICtrlRead($iCheckboxID) = $GUI_CHECKED) Then Return _GUICtrlPasswordDisplay($iPasswordID)
    Return _GUICtrlPasswordDisplay($iPasswordID, 0)
EndFunc   ;==>_GUICtrlPasswordCheckbox

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPasswordDisplay
; Description ...: Sets the visibility of the characters in any password styled input control.
; Syntax.........: _GUICtrlPasswordDisplay($iPasswordID [, $iShowFlag = -1])
; Parameters ....: $iPasswordID - The control identifier (controlID) of the input control as returned by
;                  +_GUICtrlCreatePassword or GUICtrlCreateInput.
;                  $iShowFlag - [optional] A flag to determine whether or not to show the actual contents of the input control
;                  |1 = reveal letters eg. "password", this is the default.
;                  |0 = mask letters eg. "********".
; Return values .: Success      - True
;                  Failure      - False
; Author ........: smartee
; Modified.......: ProgAndy
; Remarks .......:
; Related .......: _GUICtrlCreatePassword, _GUICtrlPasswordCheckbox
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _GUICtrlPasswordDisplay($iPasswordID, $iShowFlag = -1)
    If $__DEF_PASS_CHAR = -1 Then $__DEF_PASS_CHAR = GUICtrlSendMsg($iPasswordID, $EM_GETPASSWORDCHAR, 0, 0)
    If $iShowFlag = -1 Then $iShowFlag = 1
    If $iShowFlag Then
        GUICtrlSendMsg($iPasswordID, $EM_SETPASSWORDCHAR, 0, 0)
    Else
        GUICtrlSendMsg($iPasswordID, $EM_SETPASSWORDCHAR, $__DEF_PASS_CHAR, 0)
    EndIf
    Local $aRes = DllCall("user32.dll", "int", "RedrawWindow", "hwnd", GUICtrlGetHandle($iPasswordID), "ptr", 0, "ptr", 0, "dword", 5)
    If @error Or $aRes[0] = 0 Then Return SetError(1, 0, False)
    Return True
EndFunc   ;==>_GUICtrlPasswordDisplay

Last Updated: 29-JUN-2011

Here's everything in a zip (help-file included) ;)

Download:

GUIPasswordUDFv1.4.zip

Feel free to post your comments, suggestions :alien:

-smartee

Edited by smartee
Link to comment
Share on other sites

Nice example, I never did put this Example into a UDF >> So I'm glad somebody did.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
Share on other sites

Nice example, I never did put this Example into a UDF >> So I'm glad somebody did.

Something noteworthy however, rather than redrawing by using the GUI focus, as we both previously did, I used the invalidate rect function to force that region to be redrawn. :huh2:
Link to comment
Share on other sites

OK, good to know! :huh2: At least now there isn't the selection on the Input Box. I updated the Function and referenced this forum post.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
Share on other sites

One thing I would say is I just checked the UDF using #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 and you have $aResult declared but don't actually use the variable in the Function. :huh2:

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
Share on other sites

$aResult stores the result of the DllCall, I guess its arguably unnecessary, since i do nothing else with the array, but lets leave it there so that it'll be easier to both build on, and add more error checking to the script. Nice find though :huh2:

Link to comment
Share on other sites

I use this:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("_GUICtrlEdit_TogglePassChars - Demo", 300, 80)

$nInput = GUICtrlCreateInput("My Pass", 20, 20, 190, 20)
$nButton = GUICtrlCreateButton("Toggle Pass", 220, 20, 70, 20)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nButton
            Dim $aChars[3] = ["*", "#", "x"]
            _GUICtrlEdit_TogglePassChars($hGUI, $nInput, -1, $aChars[Random(0, 2, 1)])
    EndSwitch
WEnd

Func _GUICtrlEdit_TogglePassChars($hWnd, $hCtrl, $iToggleState = -1, $sPassChar = -1)
    If Not IsHWnd($hWnd) Then
        $hWnd = WinGetHandle($hWnd)
    EndIf
    
    If Not IsHWnd($hCtrl) Then
        $hCtrl = ControlGetHandle($hWnd, "", $hCtrl)
    EndIf
    
    Local Const $EM_SETPASSWORDCHAR = 0xCC
    Local Const $EM_GETPASSWORDCHAR = 0xD2
    
    Local $iGet_Pass_Char, $iSet_Pass_Char, $iDef_Pass_Char = 9679
    Local $aRet = DllCall("user32.dll", "long", "SendMessageW", "hwnd", $hCtrl, "int", $EM_GETPASSWORDCHAR, "int", 0, "int", 0)
    
    If Not @error And $aRet[0] Then
        $iGet_Pass_Char = $aRet[0]
    EndIf
    
    If $sPassChar = -1 Then
        $iSet_Pass_Char = $iGet_Pass_Char
    Else
        If IsString($sPassChar) Then
            $iSet_Pass_Char = Asc($sPassChar)
        Else
            $iSet_Pass_Char = $sPassChar
        EndIf
        
        $iDef_Pass_Char = $iSet_Pass_Char
    EndIf
    
    If $iToggleState = -1 Then
        If $iGet_Pass_Char <> 0 Then
            $iSet_Pass_Char = 0
        Else
            $iSet_Pass_Char = $iDef_Pass_Char
        EndIf
    ElseIf $iToggleState = 0 Then
        $iSet_Pass_Char = 0
    ElseIf $iToggleState = 1 Then
        $iSet_Pass_Char = $iDef_Pass_Char
    EndIf
    
    DllCall("user32.dll", "none", "SendMessageW", "hwnd", $hCtrl, "int", $EM_SETPASSWORDCHAR, "int", $iSet_Pass_Char, "int", 0)
    DllCall("user32.dll", "none", "InvalidateRect", "hwnd", $hCtrl, "ptr", 0, "int", 1)
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Nice UDF!

Here another variant:

;coded by UEZ 2011
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

Global Const $hGUI = GUICreate("Password", 339, 46)
Global Const $idInputPWD = GUICtrlCreateInput("", 128, 12, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
GUICtrlSetBkColor(-1, 0xFF0000)
Global Const $idLabelPWD = GUICtrlCreateLabel("Enter the passord:", 8, 14, 114, 19)
GUICtrlSetTip(-1, "Must be set to proceed! Minimum password length are 8 characters!")
GUICtrlSetFont(-1, 8, 400, 0, "Arial Black")
Global Const $idButtonGO = GUICtrlCreateButton("GO", 256, 10, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

Global $nMsg, $mcursor_old
Global $aPassword, $m = False
Global $DefaultPassChar = GUICtrlSendMsg($idInputPWD, $EM_GETPASSWORDCHAR, 0, 0)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $idButtonGO
            Exit
    EndSwitch

    $aPassword = GUIGetCursorInfo()
    If Not @error Then
        $mcursor_old = MouseGetCursor()
        If $aPassword[4] = $idInputPWD Then
            GUICtrlSendMsg($idInputPWD, $EM_SETPASSWORDCHAR, 0, 0)
            GUISetCursor(16, 1, $hGUI)
            $m = True
            InputChk()
        Else
            If $m Then
                GUICtrlSendMsg($idInputPWD, $EM_SETPASSWORDCHAR, $DefaultPassChar, 0)
                ControlFocus("", "", $hGUI)
                $m = False
                GUISetCursor($mcursor_old)
            EndIf
            InputChk()
        EndIf
    EndIf
WEnd

Func InputChk() ;avoid flickering of controls
    If Stringlen(GUICtrlRead($idInputPWD)) > 7 Then
        If BitAND(GUICtrlGetState($idButtonGO), $GUI_DISABLE) = $GUI_DISABLE Then
            GUICtrlSetState($idButtonGO, $GUI_ENABLE)
            GUICtrlSetBkColor($idInputPWD, 0xFFFFFF)
        EndIf
    Else
        If BitAND(GUICtrlGetState($idButtonGO), $GUI_ENABLE) = $GUI_ENABLE Then
            GUICtrlSetState($idButtonGO, $GUI_DISABLE)
            GUICtrlSetBkColor($idInputPWD, 0xFF0000)
        EndIf
    EndIf
EndFunc

When mouse is hovering input box password will be visible otherwise not.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks for all the feedback guys, made a couple minor changes to the DllCall and in so doing dropped that extra variable guinness talked about ;). Nothing script-breaking though :huh2:

Also added a screenshot to liven up that dreary text jungle.

Link to comment
Share on other sites

  • 3 weeks later...

Fixed a trivial bug that caused the entire window to be redrawn rather than the control itself.

Now the controls don't flicker (noticeably) when changing password visibility. Tidied UDF quite a bit also :)

Added some other stuff too, see change-log in first post.

Regards,

-smartee

Link to comment
Share on other sites

You created a .chm file :)

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
Share on other sites

Good work, this will be really useful.

PS: _GUICtrlPasswordDisplay can be shortened to this:

; Author ........: smartee
; Modified.......: ProgAndy
Func _GUICtrlPasswordDisplay($hWnd, $iCtrlID, $iShowFlag)
    If ($__DEF_PASS_CHAR = -1) Then $__DEF_PASS_CHAR = GUICtrlSendMsg($iCtrlID, $EM_GETPASSWORDCHAR, 0, 0)
    If ($iShowFlag = 1) Then
        GUICtrlSendMsg($iCtrlID, $EM_SETPASSWORDCHAR, 0, 0)
    Else
        GUICtrlSendMsg($iCtrlID, $EM_SETPASSWORDCHAR, $__DEF_PASS_CHAR, 0)
    EndIf
    Local $aRes = DllCall("user32.dll", "int", "RedrawWindow", "hwnd", GUICtrlGetHandle($iCtrlID), "ptr", 0, "ptr", 0, "dword", 5)
    If @error Or $aRes[0] = 0 Then Return SetError(1, 0, False)
    Return True
EndFunc   ;==>_GUICtrlPasswordDisplay

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

@guinness: ;) Yup, quite a snap actually, once you format your UDF correctly; Jos, Gary etc. already did all the work, its all automated really :)

@ProgAndy: Neat! ;) Thank you. I will update the first post shortly.

Link to comment
Share on other sites

I knew about the UDF creation page but totally missed this >> http://www.autoitscript.com/autoit3/udfs/UDF_BuildTemplates.htm

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
Share on other sites

Updated again, parameters for most functions have been updated (script-breaking) see change-log in first post for details.

I knew about the UDF creation page but totally missed this >> http://www.autoitscript.com/autoit3/udfs/UDF_BuildTemplates.htm

Don't forget to check out the AutoIt docs source, that's where the text files spring to life as html :)

Regards

-smartee

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