A Few Questions about using Subclassing when defining an "Extended" custom control

Robert Gustafson 606 Reputation points
2021-04-15T21:06:56.357+00:00

WHAT I HAVE:
Visual Basic 2019, .NET 4+, WinForms

MY PROBLEM:
I want to create a control that inherits from another and implements features not normally supported by the base class using subclassing. The subclassing would be implemented in the code defining the derived class. A few questions:

  1. When defining the window handle for SetWindowSubclass and other related procedures (I'm trying to capture messages for an auxiliary handle not directly exposed by the control itself), should I use Me.Handle (the handle of the derived class) or MyBase.Handle (the handle of the base class) for the hWnd parameter?
  2. Since there are likely to be multiple instances of the derived class, and they're all going to use the same "target procedure" to intercept messages, does the uIdSubclass parameter for SetWindowSubclass have to be different for each instance, or can it be the same? (If it has to be unique, how can I guarantee that?)
  3. Logically, I would invoke SetWindowSubclass after MyBase.OnHandleCreated from within the OnHandleCreated method. Should I also invoke RemoveWindowSubclass before MyBase.OnHandleDestroyed from within the OnHandleDestroyed method? (Particularly if the handle being subclassed is actually an auxiliary one, like the one for the drop-down list of a combo box?)

Please provide any advice/code ASAP, and in VB.NET.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,811 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,386 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,542 questions
{count} votes