Creating a Password-Style Macro Dialog Text BoxLast reviewed: August 4, 1997Article ID: Q114299 |
6.00 6.00a 6.00c 7.00
WINDOWS
kbusage kbmacro
The information in this article applies to:
SUMMARYIn Word for Windows, there is no intrinsic setting for a password-style edit control. However, you can generate code to perform this function using the existing edit control. To create a dialog that prompts for a password, use SendMessage (Windows API function call) with the constant of EM_SETPASSWORDCHAR.
MORE INFORMATIONThe following example demonstrates how to design a text box that will accept a user's password as input. It displays an asterisk (*) for each character entered. Use the SendMessage API function call to create this dialog. After you set the focus to the desired edit control, you must send a message to the window's message queue that will reset the displayed character for the control. The argument EM_SETPASSWORDCHAR, as the second parameter to SendMessage, sets the desired text character to display based on the value specified by the third argument. The SendMessage function requires the following parameters for setting the password Character
SendMessage Lib "User"(hWnd As Integer, wMsg As Integer, wParam As Integer, lParam As String) As Longwhere:
hWnd Specifies the handle to the edit control. wMsg Specifies the window's message. wParam Specifies the password character to display. lParam Is not used. ExampleWARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Word 7.0
Declare Function SendMessageA Lib "User32"(hWnd As Long, wMsg As Integer,wParam As Integer, lParam As String) As Long Declare Function GetFocus Lib "User32"() As LongDim Shared WM_USER, PasChar, EM_SETPASSWORDCHAR Sub MAIN WM_USER = 1024 EM_SETPASSWORDCHAR = 204 PasChar = Asc("*") Begin Dialog UserDialog 181, 78, "Password", .dlgfun OKButton 22, 6, 140, 21 PushButton 22, 30, 140, 21, "Enter Password", .Push1 TextBox 22, 54, 160, 18, .TextBox1 End Dialog Dim dlg As UserDialog x = Dialog(dlg) End SubFunction dlgfun(id$, action, wValue) Select Case action Case 1 DlgVisible "TextBox1", 0 Case 2 If id$ = "Push1" Then DlgVisible "TextBox1", 1 DlgFocus "TextBox1" hWnd = GetFocus retVal = SendMessageA(hWnd, EM_SETPASSWORDCHAR, PasChar, "") dlgFun = 1 End If If id$ = "OK" And Len(DlgText$("TextBox1")) > 0 Then MsgBox "Your Password is:" + Chr$(10) + DlgText$("TextBox1") End If Case 3 Case 4 Case 5 Case 6 Case Else End SelectEnd Function
Word 6.0Declare Function SendMessage Lib "User"(hWnd As Integer, wMsg AsInteger, wParam As Integer, lParam As String) As Long Declare Function GetFocus Lib "User"() As IntegerDim Shared WM_USER, PasChar, EM_SETPASSWORDCHAR Sub MAIN WM_USER = 1024 EM_SETPASSWORDCHAR = WM_USER + 28 PasChar = Asc("*") Begin Dialog UserDialog 181, 78, "Password", .dlgfun OKButton 22, 6, 140, 21 PushButton 22, 30, 140, 21, "Enter Password", .Push1 TextBox 22, 54, 160, 18, .TextBox1 End Dialog Dim dlg As UserDialog x = Dialog(dlg) End SubFunction dlgfun(id$, action, wValue) Select Case action Case 1 DlgVisible "TextBox1", 0 Case 2 If id$ = "Push1" Then DlgVisible "TextBox1", 1 DlgFocus "TextBox1" hWnd = GetFocus retVal = SendMessage(hWnd, EM_SETPASSWORDCHAR, PasChar, "") dlgFun = 1 End If If id$ = "OK" And Len(DlgText$("TextBox1")) > 0 Then MsgBox "Your Password is:" + Chr$(10) + DlgText$("TextBox1") End If Case 3 Case 4 Case 5 Case 6 Case Else End SelectEnd Function
REFERENCES"Microsoft Software Development Kit (SDK) for Microsoft Windows Operating System Version 3.1" Kbcategory: kbusage kbmacro KBSubcategory: |
Additional reference words: 6.00 6.00a winword wordbasic word6 word7
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |