ClickChild Event

Applies to:  Subclasser object
See also:  ClickControl event, Event Index

The ClickChild event occurs when the subclassed window has captured mouse input, and a mouse button is pressed whilst the mouse pointer is within a child window of the subclassed window and then released within the same window.

Syntax:

Private Sub object_ClickChild(ByVal hWndChild As Long, ByVal Button As MouseButtonConstants, ByVal Shift As Boolean, ByVal Control As Boolean, ByVal x As Long, ByVal y As Long, Cancel As Boolean)

The ClickChild event syntax has these parts:

Part Description
object The name of a SubClasser object, declared using WithEvents.
hWndChild The handle of the child window in which the mouse button was clicked.
Button A value indicating which button was clicked.  Can be any one of the following values:
  • vbLeftButton
  • vbMiddleButton
  • vbRightButton
Shift A boolean value indicating the state of the Shift key.  A value of True indicates that one or both Shift keys are down.
Control A boolean value indicating the state of the Control key.  A value of True indicates that one or both Control keys are down
x The x coordinate (in pixels) of the mouse pointer at the time it was clicked, relative to the top-left corner of the window or control.
y The y coordinate (in pixels) of the mouse pointer at the time it was clicked, relative to the top-left corner of the window or control.
Cancel A boolean flag indicating whether to pass the WM_CLICK message which generated this event onto the child window.  Setting this flag has no discernable effect.

Remarks:

The ClickChild event is only raised if the subclassed window has captured mouse input.  To enable the ClickChild event, call TrackMouse in the MouseEnter event.

In order to retain mouse input capture when the mouse pointer enters a child window, cancel any MouseLeave events where Side = siChildWindow.  This will disable normal processing of mouse messages by child windows, and will allow the Subclasser object to handle messages that would normally be processed by child windows.

Example:

'This example disables normal handling of mouse events
'by controls on the form, and outputs a message whenever
'the user clicks on a control on the form.

Option Explicit

Private WithEvents
objmSubclasser As Subclasser

Private Sub
Form_Load()
    'Subclass this form
    Set
objmSubclasser = SubClassWindow(hWnd)
End Sub

Private Sub
objmSubclasser_MouseEnter()
    'Capture mouse input to enable the ClickChild event.
    objmSubclasser.TrackMouse
End Sub

Private Sub
objmSubclasser_MouseLeave(ByVal Side As AkemiPowerPack.SideConstants, Cancel As Boolean)
    If
Side = siChildWindow Then
        'Cancel the MouseLeave event if the mouse pointer
        'has entered a child window.  This will have the
        'effect of retaining mouse capture until the
        'mouse pointer leaves the SubClassed window
        'all together.

       
Cancel = True
    End If
End Sub

Private Sub
objmSubclasser_ClickChild(ByVal hWndChild As Long, ByVal Button As MouseButtonConstants, ByVal Shift As Boolean, ByVal Control As Boolean, ByVal x As Long, ByVal y As Long, Cancel As Boolean)
    Debug.Print "ClickChild"
End Sub

 

Home

Copyright and Disclaimer