CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Apr 2010
    Posts
    1

    Custom msgbox and password box

    Hello, I am Subrata das from Kolkata, India. I am facing problem while upgrading a vb6 module to vb2008 module. After upgradation the module gives build error. The module after upgradation is given below;

    Code:
    Option Strict Off
    Option Explicit On
    Module Module1
    	'**************************************
    	' Name: Custom MessageBox And Password I
    	'     nputBox
    	' Description:MessageBox with custom tex
    	'     t on buttons,
    	'InputBox for password input with *****,
    
    
    	Private Declare Function GetCurrentThreadId Lib "kernel32" () As Integer
        Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As Integer, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
        Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Integer) As Integer
        Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hwndParent As Integer, ByVal hwndChildAfter As Integer, ByVal lpszClass As String, ByVal lpszWindow As String) As Integer
        Private Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" (ByVal HWND As Integer, ByVal lpString As String) As Integer
        Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal HWND As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
    
    	'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
        'Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal HWND As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As Any) As Integer----------------------before chamge
        Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal HWND As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As String) As Integer '--------------------after change
        Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Integer, ByVal lpCursorName As String) As Integer
        Private Const HCBT_ACTIVATE As Short = 5
    	Private Const WH_CBT As Short = 5
    	Private hHook As Integer
    	Private ButtonText(3) As String
    	Private PasswordChar As Byte
    
    
        Private Function ChangeButtonsText(ByVal lMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
            Dim t As Short
            Dim cName As String
            Dim Length As Integer
            Dim Btn(3) As Integer
    
    
            If lMsg = HCBT_ACTIVATE Then
                Btn(0) = FindWindowEx(wParam, 0, vbNullString, vbNullString)
    
                For t = 1 To 3
                    Btn(t) = FindWindowEx(wParam, Btn(t - 1), vbNullString, vbNullString)
                    If Btn(t) = 0 Then Exit For
                Next t
    
    
                For t = 0 To 3
    
                    If (Btn(t) <> 0) And (Btn(t) <> wParam) Then
                        cName = Space(255)
                        Length = GetClassName(Btn(t), cName, 255)
                        cName = Left(cName, Length)
    
                        If UCase(cName) = "BUTTON" Then
                            If ButtonText(t) <> vbNullString Then SetWindowText(Btn(t), ButtonText(t))
                        End If
                    End If
                Next t
                UnhookWindowsHookEx(hHook)
            End If
            ChangeButtonsText = False
        End Function
    
    
        Private Function SetPasswordChar(ByVal lMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
            Const EM_SETPASSWORDCHAR As Integer = &HCC
            Dim t As Short
            Dim cName As String
            Dim Length As Integer
            Dim Btn(3) As Integer
    
            If lMsg = HCBT_ACTIVATE Then
                Btn(0) = FindWindowEx(wParam, 0, vbNullString, vbNullString)
    
                For t = 1 To 3
                    Btn(t) = FindWindowEx(wParam, Btn(t - 1), vbNullString, vbNullString)
                    If Btn(t) = 0 Then Exit For
                Next t
    
                For t = 0 To 3
    
                    If (Btn(t) <> 0) And (Btn(t) <> wParam) Then
                        cName = Space(255)
                        Length = GetClassName(Btn(t), cName, 255)
                        cName = Left(cName, Length)
                        If LCase(cName) = "edit" Then SendMessage(Btn(t), EM_SETPASSWORDCHAR, PasswordChar, 0)
                    End If
                Next t
                UnhookWindowsHookEx(hHook)
            End If
            SetPasswordChar = False
        End Function
    
        Public Function CustomMsgBox(ByVal zMessage As String, Optional ByVal zButtons As MsgBoxStyle = MsgBoxStyle.OkOnly, Optional ByVal zTitle As String = vbNullString, Optional ByVal Button1Text As String = vbNullString, Optional ByVal Button2Text As String = vbNullString, Optional ByVal Button3Text As String = vbNullString) As MsgBoxResult
    
            Dim Thread As Integer
    
            ButtonText(0) = Button1Text
            ButtonText(1) = Button2Text
            ButtonText(2) = Button3Text
            Thread = GetCurrentThreadId()
    
            hHook = SetWindowsHookEx(WH_CBT, AddressOf ChangeButtonsText, 0, Thread)
    
            If zTitle = vbNullString Then
                CustomMsgBox = MsgBox(zMessage, zButtons)
            Else
                CustomMsgBox = MsgBox(zMessage, zButtons, zTitle)
            End If
        End Function
    
    
        Public Function PasswordBox(ByVal zMessage As String, Optional ByVal zTitle As String = vbNullString, Optional ByVal zPasswordChar As Byte = 42) As String
            Dim Thread As Integer
            PasswordChar = zPasswordChar
            Thread = GetCurrentThreadId()
            'UPGRADE_WARNING: Add a delegate for AddressOf SetPasswordChar Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="E9E157F7-EF0C-4016-87B7-7D7FBBC6EE08"'
            hHook = SetWindowsHookEx(WH_CBT, AddressOf SetPasswordChar, 0, Thread)
    
    
            If zTitle = vbNullString Then
                PasswordBox = InputBox(zMessage)
            Else
                PasswordBox = InputBox(zMessage, zTitle)
            End If
        End Function
    End Module
    Last edited by HanneSThEGreaT; April 20th, 2010 at 07:03 AM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured