#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GUIComboBoxEx.au3>
#include <WindowsConstants.au3>
Global $iPass_Combo_Edit_Changed = 0
Global $iPass_Combo_Sel_Changed = 0
Global $iShow_Password = 0
Global $iPasswords_Limit = 5
Global $sBuffer = ''
Global $aBuffer[1]
Global $sDefault_Pass_List = 'password|пароль|12345|qwerty'
Global $sDefault_Password = '12345'
$hGUI = GUICreate('Password ComboBox', 240, 100)
$iPass_Combo = GUICtrlCreateCombo('', 10, 10, 220, 50)
$hPass_Combo = GUICtrlGetHandle($iPass_Combo)
$aPassword_List = StringSplit($sDefault_Pass_List, '|')
For $i = 1 To $aPassword_List[0]
_Combo_Add_Password($aPassword_List[$i])
Next
_GUICtrlComboBox_SetEditText($iPass_Combo, StringRegExpReplace($sDefault_Password, '.', '*'))
$sBuffer = $sDefault_Password
$iShowPass_CB = GUICtrlCreateCheckbox('Show passwords', 10, 40)
$iAddPass_Bttn = GUICtrlCreateButton('OK', 160, 70, 70, 20, $BS_DEFPUSHBUTTON)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState(@SW_SHOW, $hGUI)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $iShowPass_CB
_Combo_Toggle_Password()
Case $iAddPass_Bttn
_Combo_Add_Password()
EndSwitch
_Combo_Edit_Changed_Check()
_Combo_Sel_Changed_Check()
WEnd
Func _Combo_Toggle_Password()
$iPass_Combo_Edit_Changed = 1
$iPass_Combo_Sel_Changed = 1
$iShow_Password = BitAND(GUICtrlRead($iShowPass_CB), $GUI_CHECKED)
$iCount = _GUICtrlComboBox_GetCount($iPass_Combo)
$sData = ''
$sSel_Item = $sBuffer
For $i = 0 To $iCount-1
$sIndex = ''
_GUICtrlComboBoxEx_GetItemText($iPass_Combo, $i, $sIndex)
$sIndex = Number(StringLeft($sIndex, 1))
If $iShow_Password Then
$sData &= $i + 1 & '. ' & $aBuffer[$sIndex] & '|'
Else
$sData &= $i + 1 & '. ' & StringRegExpReplace($aBuffer[$sIndex], '.', '*') & '|'
EndIf
Next
GUICtrlSetData($iPass_Combo, '')
GUICtrlSetData($iPass_Combo, $sData)
If Not $iShow_Password Then
$sSel_Item = StringRegExpReplace($sBuffer, '.', '*')
EndIf
_GUICtrlComboBox_SetEditText($iPass_Combo, $sSel_Item)
$iPass_Combo_Edit_Changed = 0
$iPass_Combo_Sel_Changed = 0
EndFunc
Func _Combo_Add_Password($sBuff = '')
If _GUICtrlComboBox_GetCount($iPass_Combo) = $iPasswords_Limit Then
MsgBox(48, 'Attention', StringFormat('Passwords limit (%i) is reached.', $iPasswords_Limit), 0, $hGUI)
Return
EndIf
$iPass_Combo_Edit_Changed = 1
$iPass_Combo_Sel_Changed = 1
If $sBuff <> '' Then $sBuffer = $sBuff
$aBuffer[0] += 1
ReDim $aBuffer[$aBuffer[0]+1]
$aBuffer[$aBuffer[0]] = $sBuffer
If $iShow_Password Then
GUICtrlSetData($iPass_Combo, $aBuffer[0] & '. ' & $sBuffer)
Else
GUICtrlSetData($iPass_Combo, $aBuffer[0] & '. ' & StringRegExpReplace($sBuffer, '.', '*'))
EndIf
_GUICtrlComboBox_SetEditText($iPass_Combo, '')
GUICtrlSetState($iPass_Combo, $GUI_FOCUS)
$sBuffer = ''
$iPass_Combo_Edit_Changed = 0
$iPass_Combo_Sel_Changed = 0
EndFunc
Func _Combo_Edit_Changed_Check()
If $iPass_Combo_Edit_Changed = 0 Then Return
$sData = GUICtrlRead($iPass_Combo)
If StringLen($sData) < StringLen($sBuffer) Then
$sBuffer = StringTrimRight($sBuffer, 1)
Else
$sBuffer &= StringRight($sData, 1)
EndIf
If $iShow_Password Then
_GUICtrlComboBox_SetEditText($iPass_Combo, $sData)
Else
_GUICtrlComboBox_SetEditText($iPass_Combo, StringRegExpReplace($sData, '.', '*'))
EndIf
$iPass_Combo_Edit_Changed = 0
EndFunc
Func _Combo_Sel_Changed_Check()
If $iPass_Combo_Sel_Changed = 0 Then Return
$iPass_Combo_Edit_Changed = 1
$sIndex = Number(StringLeft(GUICtrlRead($iPass_Combo), 1))
$sBuffer = $aBuffer[$sIndex]
If $iShow_Password Then
_GUICtrlComboBox_SetEditText($iPass_Combo, $sBuffer)
Else
_GUICtrlComboBox_SetEditText($iPass_Combo, StringRegExpReplace($sBuffer, '.', '*'))
EndIf
$iPass_Combo_Sel_Changed = 0
$iPass_Combo_Edit_Changed = 0
EndFunc
Func WM_COMMAND($hWnd, $nMsg, $wParam, $lParam)
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
If $iPass_Combo_Edit_Changed Or $iPass_Combo_Sel_Changed Then Return $GUI_RUNDEFMSG
Switch $nID
Case $iPass_Combo
Switch $nNotifyCode
Case $CBN_EDITCHANGE, $CBN_EDITUPDATE
$iPass_Combo_Edit_Changed = 1
Case $CBN_SELCHANGE
$iPass_Combo_Sel_Changed = 1
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc