Ok, I'm still trying to make this Comctl32.dll subclassing work the way I'd like.
Everything is going along pretty well ... except, when I subclass and then break (for debugging purposes), I've lost several debugging features. Edwardo and I both hinted at this in another thread, but I'd like to just get more clear on it in this one.
Ok, here it is as simple as I can make it. The following code goes in Module1 (that name is required).
Code:
Option Explicit
'
Private Const WM_DESTROY = &H2&
'
Public Declare Function SetWindowSubclass Lib "comctl32.dll" Alias "#410" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long, Optional ByVal dwRefData As Long) As Long
Public Declare Function GetWindowSubclass Lib "comctl32.dll" Alias "#411" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long, pdwRefData As Long) As Long
Public Declare Function RemoveWindowSubclass Lib "comctl32.dll" Alias "#412" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long) As Long
Public Declare Function NextSubclassProcOnChain Lib "comctl32.dll" Alias "#413" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'
Public Function Proc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal uIdSubclass As Long, ByVal dwRefData As Long) As Long
If uMsg = WM_DESTROY Then
RemoveWindowSubclass hWnd, AddressOf Module1.Proc, hWnd
Proc = NextSubclassProcOnChain(hWnd, uMsg, wParam, lParam)
Exit Function
End If
' Nothing actually done.
Proc = NextSubclassProcOnChain(hWnd, uMsg, wParam, lParam)
End Function
And then, a Form1 with two buttons on it (Command1 and Command2), and then this code:
Code:
Option Explicit
Private Sub Form_Load()
SetWindowSubclass Me.hWnd, AddressOf Proc, Me.hWnd
End Sub
Private Sub Command1_Click()
Debug.Print "1111"
Debug.Print "2222"
Debug.Print "3333"
Stop
Debug.Print "7777"
Debug.Print "8888"
Debug.Print "9999"
End Sub
Private Sub Command2_Click()
RemoveWindowSubclass hWnd, AddressOf Module1.Proc, hWnd
End Sub
Now, the form will automatically subclass itself (but the subclassing doesn't even do anything).
Click the Command1 button, thereby hitting the "Stop" statement. We've lost several options on our context menu:
We've also lost all ability to use the IDE's menu:
Also the debug (immediate) window is inaccessible.
As a further note, the debug keys
do still work (F5, F8, shift+F8, ctrl+shift+F9, etc).
Does everyone else have these same problems?
Is it something to do with my particular version of Comctl32.dll?
One last FYI: Once we un-subclass, we get all our functionality back.
Now, in my main project, I've got the following option (when executing in the IDE), but it'd be nice if I could still more easily trace through my code even if I'm subclassing.
Thanks,
Elroy