標題:
[發問]
在自定表單中 如何 請輸密碼時 show **** 代替 文字數字 謝謝!
[打印本頁]
作者:
user999
時間:
2011-12-2 12:38
標題:
在自定表單中 如何 請輸密碼時 show **** 代替 文字數字 謝謝!
自定表單
strPassword = InputBox("請輸入密碼:", "訊息視窗")
作者:
Hsieh
時間:
2011-12-3 21:43
本帖最後由 Hsieh 於 2011-12-3 21:57 編輯
回復
1#
user999
http://blog.xuite.net/crdotlin/excel/13554651
'一般模組 Module1 程式碼
Option Explicit
'API宣告
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'timeSetEvent函數請參考:http://msdn2.microsoft.com/en-us/library/ms713423.aspx
Private Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, _
ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
Private Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long
Private Const EM_SETPASSWORDCHAR = &HCC
Dim lTimeID As Long 'Timer ID
Const pswdInputBoxTitle = "pswdInputBox" '輸入密碼的對話框標題
'TimeProc callback 函數請參考:http://msdn2.microsoft.com/en-us/library/ms713420.aspx
Sub TimeProc(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, _
ByVal dw1 As Long, ByVal dw2 As Long)
Dim hwd As Long '輸入密碼的對話框句柄
'VBA InputBox對話框之Class Name是 "#32770",
'標題為 "pswdInputBox", 這是在InputBox函數的Title引述中自訂的
'請注意Application.InputBox方法所出現的對話框Class Name是 "bosa_sdm_XL9"
hwd = FindWindow("#32770", pswdInputBoxTitle)
If hwd <> 0 Then '若對話框存在
'取得輸入的文字框句柄, 該文字框的Class Name是"Edit", 無標題,
'而Application.InputBox方法所出現的對話框之文字框的Class Name是"EDTBX"
hwd = FindWindowEx(hwd, 0, "Edit", vbNullString)
'設定密碼字元為 "*", "*"的ASCII碼為42
SendMessage hwd, EM_SETPASSWORDCHAR, 42, 0
'設定完成, 取消計時器
timeKillEvent lTimeID
End If
End Sub
'自定義函數pswdInputBox, 是一個輸入密碼使用的InputBox, 輸入的內容都以 "*" 顯示.
Function pswdInputBox() As Variant
'啟動一個特定的Timer事件, 0.01秒延遲, 0.05秒看一次
lTimeID = timeSetEvent(10, 50, AddressOf TimeProc, 1, 1)
'顯示InputBox對話框
pswdInputBox = InputBox(Prompt:="請輸入編輯密碼", Title:=pswdInputBoxTitle)
End Function
複製代碼
'表單模組Userform1程式碼
表單上設置一個標籤Label1、及1個按鈕CommandButton1
[attach]8706[/attach]
Private Sub CommandButton1_Click()
Label1.Caption = ""
If pswdInputBox <> 123456 Then
'密碼不正確, 顯示訊息
Label1.Caption = "對不起,密碼錯誤,你無編輯權限!"
Else
Label1.Caption = "歡迎使用本系統"
End If
End Sub
複製代碼
作者:
user999
時間:
2011-12-5 08:34
回復
2#
Hsieh
非常謝謝您! 看起來好複雜,我會好好學習,測試好用,真感謝.
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)