Solved

DblClick event for MaskEdBox

Posted on 1998-05-20
3
543 Views
Last Modified: 2012-05-07
We need to detect when the user double-clicks on a Masked Edit box in VB 5.0.  Unfortunately, the MaskEdBox control does not have the DblClick event, nor the Click event (and we're puzzled as to why not).  Seeking help.  Thanks in advance.
0
Comment
Question by:pbrooks
3 Comments
 
LVL 5

Accepted Solution

by:
bin_huwairib earned 200 total points
ID: 1456086
pbrooks,

You can build your own windows message handler for Masked Edit control with AddressOf operator.

Example
=======
1- Add form1 to project1.
2- Add module1 to project1.
3- Add maskedit control to form1.

=== paste this code in form1 ===
Private Sub Form_Click()
 UnHook
End Sub

Private Sub Form_Load()
 gHW = MaskEdBox1.hWnd
 Hook
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
 UnHook
End Sub


=== paste this code in module1 ===
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
           (ByVal lpPrevWndFunc As Long, _
            ByVal hWnd As Long, _
            ByVal Msg As Long, _
            ByVal wParam As Long, _
            ByVal lParam As Long) As Long
 
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
           (ByVal hWnd As Long, _
            ByVal nIndex As Long, _
            ByVal dwNewLong As Long) As Long
 
    Public Const GWL_WNDPROC = -4
 
    Public Const WM_LBUTTONDBLCLK = &H203

    Global lpPrevWndProc As Long
    Global gHW As Long
 
    Public Sub Hook()
        lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
                                     AddressOf WindowProc)
    End Sub
 
    Public Sub UnHook()
        Dim lngReturnValue As Long
        lngReturnValue = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    End Sub
 
    Function WindowProc(ByVal hw As Long, _
                        ByVal uMsg As Long, _
                        ByVal wParam As Long, _
                        ByVal lParam As Long) As Long
     
        Select Case uMsg
            Case WM_LBUTTONDBLCLK
                Form1.Caption = "Double Click.."
               
            Case Else
                WindowProc = CallWindowProc(lpPrevWndProc, hw, _
                                           uMsg, wParam, lParam)
        End Select
    End Function


Best regards
Bin Huwairib
0
 

Author Comment

by:pbrooks
ID: 1456087
Excellent!  This is exactly the answer I was looking for.  My hat's off to the expert  for a fast and accurate solution.

0
 

Expert Comment

by:rogerkj
ID: 2644493
I have the same problem as pbrooks except that my masked edit box is on a UserControl instead of a Form.
I tried your answer but in the Select case I did not have access to the usercontrol (I wanted to call a sub on the usercontrol).

   Select Case uMsg
      Case WM_LBUTTONDBLCLK
          no access to UC
      Case Else

Any ideas?

If you do I can post a question so you can get points for your answer.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now