Where to Start

The most important thing that you should remember is to save your work often. I tell you this from experience. If your subclassing application crashes while running in the Visual Basic IDE, the entire VB environment including the running application is lost. All unsaved code also is lost.

There are reliable ways to debug subclassing applications. I will present the ones I use regularly here.

When writing a subclassing application, it is usually better to start simple. Write the subclassing code using only a minimal window procedure function. By this, I mean do not handle any messages within this function; only pass the messages on to the original window procedure. This is the code for a minimal window procedure:

Public Function WinProc(ByVal hwnd As Long, ByVal uMsg As Long, _
                ByVal wParam As Long, ByVal lParam As Long) As Long

   WinProc = CallWindowProc(OrigWndProc, hwnd, uMsg, wParam, lParam)
End Function

This allows you to test your subclassing code alone. After all problems are resolved with the subclassing code, you can proceed, adding the necessary code to the subclassed window procedure. If there is a problem after adding code to the subclassed window procedure, you can narrow it down to this new code.

Subclassing Checklist

Before running your subclassing application for the first time, it is a good idea to run through a basic checklist to verify that all pieces required for subclassing are accounted for. You can use the following checklists as guideline for verifying ...

Get Subclassing and Hooking with Visual Basic now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.