UnHook子类的安全方法(Unhook Subclassing When Windows is Ready)
Unhook Subclassing When Windows is
Ready
Don’t unhook your Windows procedures from Form_Unload
when
subclassing forms. When you subclass forms, the hook is often set
during Form_Load with code like this:
OriginalProc
= SetWindowLong Me.hWnd, _
GWL_WNDPROC, AddressOf MyWindowProc
subclassing forms. When you subclass forms, the hook is often set
during Form_Load with code like this:
A common mistake is forgetting to put the corresponding
unhook
call in your Form_Unload event:(很容易忘了在Form_Unload 事件写如下代码)
call in your Form_Unload event:(很容易忘了在Form_Unload 事件写如下代码)
If you forget to reinstate the old procedure in your
Form_Unload
event, it’s bye-bye VB. Instead, add this code within your
event, it’s bye-bye VB. Instead, add this code within your
subclassing
procedure:(其实可以在安装子类时就写上如下窗口过程代码,就可以了,而且不怕进入调试模式!!!!)
Select Case Msg
Case WM_NCDESTROY
If
OriginalProc <> 0 Then
Call SetWindowLong(hWnd, _
GWL_WNDPROC, OriginalProc)
OriginalProc=0
End If
Case ...
Select Case Msg
Case WM_NCDESTROY
Case ...
This code restores the original procedure automatically when the
window is destroyed. To make it even safer, place all your
subclassing code in a separate DLL and debug your subclassed
forms without worrying about the Integrated Development Environment
(IDE) crashing. You can always move the code back to
your EXE when it’s fully debugged.
浙公网安备 33010602011771号