Subclassing & encapulating controls

Xancholy

Well-known member
Joined
Aug 29, 2006
Messages
143
Programming Experience
Beginner
Please can somone help me understand how to subclass or encapsulate a control so that I can govern some of the control's default behaviour.

Eg: allow focus in Mytextbox only when user double clicks (double-click to edit)

Thanks very much
 
What value have you defined WM_LBUTTONDOWN message to be? Sometimes you just have to stop trying and start thinking ;)
 
OK, I am thinking & trying. Because control is still reading double-click event, So I trapped the WM_LBUTTONDBLCLK. A big thank you to JMC and JohnH for helping out. Cheers vbdotnetforums. This is why I participate here.

VB.NET:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim s As SubclassHWND = New SubclassHWND()
        s.AssignHandle(Me[COLOR="Red"].AxQTControl1.[/COLOR]Handle)
        ' Now s should be listening to the AxQTControl1's messages.
        AxQTControl1.URL = "c:\tempfiles\u-100.mpg"
    End Sub
End Class

Public Class SubclassHWND
    Inherits NativeWindow

    Private Const WM_LBUTTONDOWN As Integer = &H201
    Private Const WM_LBUTTONDBLCLK As Integer = &H203

    Protected Overloads Overrides Sub WndProc(ByRef m As Message)
        ' do whatever custom processing you need for

        Select Case m.Msg
            Case WM_LBUTTONDOWN
                ' Disable mousedown/click

            Case WM_LBUTTONDBLCLK
                ' Disable double click

            Case Else
                'It is important to pass unhandled messages back to the default message handler.
                MyBase.WndProc(m)
        End Select

    End Sub
End Class
 
Last edited:
Here's another question:

How can I handle the right-click event on this subclassed control to show a contextmenu?
 
There's a WM_RBUTTONUP message too.
 
I've added contextmenustrip1 to the form.

How can I trigger it with subclassed control's WM_RBUTTONDOWN ?

How do I wire WM_CONTEXT to contextmenustrip1 to display it on right click ?
 
Last edited:
Declare and raise an event.
 
Back
Top