+ Reply to Thread
Results 1 to 4 of 4

*** mask password in inputbox For 64 Bit Version

Hybrid View

  1. #1
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    *** mask password in inputbox For 64 Bit Version

    hi,
    i found this code on net.......
    this code makes a password mask in inputbox, And this version will work 64 bit version, Hope this will help

    Option Explicit
    
    #If VBA7 Then
    
    Private Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As LongPtr, ByVal ncode As Long, ByVal wParam As LongPtr, lParam As Any) As Long
    Private Declare PtrSafe Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As LongPtr
    Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As LongPtr, ByVal dwThreadId As Long) As LongPtr
    Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As LongPtr) As Long
    Private Declare PtrSafe Function SendDlgItemMessage Lib "user32" Alias "SendDlgItemMessageA" (ByVal hDlg As LongPtr, ByVal nIDDlgItem As Long, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
    Private Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As LongPtr, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long
    '
    '
    #Else
    Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
        ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
    
    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
        (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    
    Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    
    Private Declare Function SendDlgItemMessage Lib "user32" Alias "SendDlgItemMessageA" _
    (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, _
    ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    
    Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
    #End If
    
    '~~> Constants to be used in our API functions
    Private Const EM_SETPASSWORDCHAR = &HCC
    Private Const WH_CBT = 5
    Private Const HCBT_ACTIVATE = 5
    Private Const HC_ACTION = 0
    
    #If VBA7 Then
        Private hHook As LongPtr
    #Else
        Private hHook As Long
    #End If
     
    Public Function NewProc(ByVal lngCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Dim RetVal
        Dim strClassName As String, lngBuffer As Long
     
        If lngCode < HC_ACTION Then
            NewProc = CallNextHookEx(hHook, lngCode, wParam, lParam)
            Exit Function
        End If
     
        strClassName = String$(256, " ")
        lngBuffer = 255
     
        If lngCode = HCBT_ACTIVATE Then    'A window has been activated
     
            RetVal = GetClassName(wParam, strClassName, lngBuffer)
     
            If Left$(strClassName, RetVal) = "#32770" Then  'Class name of the Inputbox
     
                'This changes the edit control so that it display the password character *.
                'You can change the Asc("*") as you please.
                SendDlgItemMessage wParam, &H1324, EM_SETPASSWORDCHAR, Asc("*"), &H0
            End If
     
        End If
     
        'This line will ensure that any other hooks that may be in place are
        'called correctly.
        CallNextHookEx hHook, lngCode, wParam, lParam
     
    End Function
    Public Function InputBoxDK(Prompt As String, Optional Title As String, _
                               Optional Default As String, _
                               Optional Xpos As LongPtr, _
                               Optional Ypos As LongPtr, _
                               Optional Helpfile As String, _
                               Optional Context As LongPtr) As String
    
        Dim lngModHwnd As LongPtr, lngThreadID As Long
    
        '// Lets handle any Errors JIC! due to HookProc> App hang!
        On Error GoTo ExitProperly
        lngThreadID = GetCurrentThreadId
        lngModHwnd = GetModuleHandle(vbNullString)
    
        hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)
        If Xpos Then
            InputBoxDK = InputBox(Prompt, Title, Default, Xpos, Ypos, Helpfile, Context)
        Else
            InputBoxDK = InputBox(Prompt, Title, Default, , , Helpfile, Context)
        End If
    
    ExitProperly:
        UnhookWindowsHookEx hHook
    
    End Function
    Sub TestDKInputBox()
        Dim x
    
        x = InputBoxDK("Type your password here.", "Password Required")
        If x = "" Then End
        If x <> "42766786" Then
            MsgBox "You didn't enter a correct password."
            End
        End If
    
        MsgBox "Welcome Creator!", vbExclamation
    
    End Sub
    Private Sub Command1_Click()
    
    Call TestDKInputBox
    
    End Sub
    Use Code-Tags for showing your code :
    Please mark your question Solved if there has been offered a solution that works fine for you
    If You like solutions provided by anyone, feel free to add reputation using STAR *

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,366

    Re: *** mask password in inputbox For 64 Bit Version

    Public Function InputBoxDK(Prompt As String, Optional Title As String, _
                               Optional Default As String, _
                               Optional Xpos As LongPtr, _
                               Optional Ypos As LongPtr, _
                               Optional Helpfile As String, _
                               Optional Context As LongPtr) As String
    
        Dim lngModHwnd As LongPtr, lngThreadID As Long
    Maybe so but due to the red parts it won't work anymore in 32bit enviroment.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,025

    Re: *** mask password in inputbox For 64 Bit Version

    The first three don't need to be LongPtr anyway.

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: *** mask password in inputbox For 64 Bit Version

    Thanks for sharing Haroon! Very helpful and it works.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] password inputbox
    By ColemanJames in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-08-2018, 01:47 PM
  2. [SOLVED] Mask the password with *** (asterisk)
    By perko121 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-06-2017, 06:44 AM
  3. How to mask the password using this code
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 09-01-2017, 12:16 PM
  4. How to Mask Password in MsgBox ???
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-06-2016, 09:38 PM
  5. *** mask password in inputbox
    By Kvracing in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-05-2015, 08:16 PM
  6. *** mask password in inputbox
    By Kvracing in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2014, 07:55 PM
  7. Hide/Mask Cell Data Unless Password Entered
    By JimmyG. in forum Excel General
    Replies: 1
    Last Post: 06-28-2014, 04:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1