Solved

DblClick event for MaskEdBox

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

803 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