input 密码如何先显示明文再变成星号【已解决】
本帖最后由 fenhanxue 于 2017-10-15 01:43 编辑#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 214, 109, 562, 216)
$Input1 = GUICtrlCreateInput("", 64, 32, 113, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$Label1 = GUICtrlCreateLabel("密码:", 24, 32, 40, 17,$ES_PASSWORD)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd$Input1 = GUICtrlCreateInput("", 64, 32, 113, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
这样的样式,键盘打字进去,会直接显示星号
有没办法实现这样的效果:
键盘输入一个字符,这个字符先明文显示在input里,过200毫秒左右时间,再变成星号? 回复 1# fenhanxue
我記得 INPUT框有個範例是限制輸入的字元
因為它採用了時時檢測的方法可以 做到變化一下
檢測完了就 直接改為* 號然後 把真正的資料 記在另外的變數裡 回复 2# kk_lee69 #include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 449, 192, 114)
$Input1 = GUICtrlCreateInput("", 32, 40, 529, 21)
$bt = GUICtrlCreateButton('读',10,100,50,40)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $data = ''
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $bt
MsgBox(0,'',$data)
EndSwitch
check();
WEnd
Func check();
Local $temp = GUICtrlRead($Input1)
Local $len_new = StringLen($temp)
Local $len_old = StringLen($data)
If $len_new > $len_old Then
Local $temp_right = StringTrimLeft($temp,StringLen($data))
$data &= $temp_right
Local $out = ''
For $i = 1 To StringLen($data)
$out &= '*'
Next
Sleep(200)
GUICtrlSetData($Input1,$out)
ElseIf $len_new < $len_old Then
$data = StringTrimRight($data,$len_old-$len_new)
EndIf
EndFunc
这样?
感觉输快了会卡顿 回复 3# fenhanxue
理論上 輸入密碼 不會有人打快的吧 打快了 不就等同 不顯示 一樣的意思
我覺得你的做法效果不錯了
我本來的意思是如下的範例
從 MY_WM_COMMAND 去改 就好
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 629, 106, 192, 132)
$Input1 = GUICtrlCreateInput("Input1", 40, 32, 433, 24)
$Button1 = GUICtrlCreateButton("Button1", 496, 32, 105, 33)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetData($Input1, '')
EndSwitch
WEnd
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local Const $EN_CHANGE = 0x300
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local $hCtrl = $lParam
If $nID = $Input1 Then
If $nNotifyCode = $EN_CHANGE Then
$read=GUICtrlRead($Input1)
If String(StringLeft($read,1))=="0" Or String(StringLeft($read,1))=="." Then
GUICtrlSetData($Input1,StringRegExpReplace($read,'^0+|^\.+',''))
Else
$write=StringRegExpReplace($read,'[^\.0-9]+','')
$temp=StringSplit($write,".",1+2)
if UBound($temp)>2 Then $write=$temp&"."&$temp
GUICtrlSetData($Input1,$write)
EndIf
EndIf
EndIf
EndFunc 回复 4# kk_lee69
恩,还是这样用注册消息靠谱,注册消息这块一直一知半解,感谢指点啦
页:
[1]