我用熊来检查用户对象和的WindowProc计数时RemoveWindowSubclass从未减少。 因而总计用户是在任务管理器中的用户对象。
我读雷蒙德的更安全的子类在销毁窗口之前删除的子类评论,但我的测试是W / O都摧毁它。
同样的子类API是由TTF_SUBCLASS'ed工具COMCTL的工具提示类内部使用,因此,如果您正在使用非合作的提示会出现更多泄漏。
这里是VB6代码
'--- Form1.frm '
Option Explicit
Private Declare Function SetWindowSubclass Lib "comctl32" (ByVal hwnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long, ByVal dwRefData As Long) As Long
Private Declare Function DefSubclassProc Lib "comctl32" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function RemoveWindowSubclass Lib "comctl32" (ByVal hwnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long) As Long
Private Sub Command1_Click()
Call SetWindowSubclass(hwnd, AddressOf RedirectTabPaneEditWndProc, 10, ObjPtr(Me))
End Sub
Private Sub Command2_Click()
Call RemoveWindowSubclass(hwnd, AddressOf RedirectTabPaneEditWndProc, 10)
End Sub
Friend Function frWndProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
frWndProc = DefSubclassProc(hwnd, wMsg, wParam, lParam)
End Function
'--- Module1.bas '
Option Explicit
Public Function RedirectTabPaneEditWndProc( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long, _
ByVal uIdSubclass As Long, _
ByVal This As Form1) As Long
#If uIdSubclass Then '--- touch args
#End If
RedirectTabPaneEditWndProc = This.frWndProc(hwnd, wMsg, wParam, lParam)
End Function
如果有任何可以发表评论这是怎么回事,如何解决泄漏将是巨大的。
任何人,如果你正在做与SetWindowSubclass API密集的子类被警告。
干杯,
</ wqw>