Solved

DblClick event for MaskEdBox

Posted on 1998-05-20
3
561 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 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