------------usercontrol------------------
Dim Event MessageArrive()
........................
'有若干的过程和属性
----------------------------------------
----------模块--------------------------
Public Sub WinProc(hwnd as Long , uMsg as long ,lParam as long ,wParam as long )
思想就是..在类里,就是usercontrol模块里-----类命名MsgSwitch
prevWindowProc=SetWindowLong ......WndProc (位于模块)
再有个WindowProc(在类里)必须申明为Friend
Friend Function WindowProc (..........) As Long
RaiseEvent .........
CallWindowProc prevWindowProc,..........................
End Function
模块里的 WndProc函数 是这样
Public Function WndProc(.............) As Long
WndProc=GetObject(.......自己写的函数,不是API).WindowProc(.........)
CallWindowProc prevWindowProc,..........................
End Function
GetObject 申明为 Private Function GetObject(hWnd as Long) As MsgSwitch
函数关键的代码
Dim Obj As XWatcher
Dim pObj As Long
pObj = GetWindowLong(hWnd, GWL_USERDATA)
CopyMemory Obj, pObj, 4
Set GetObject = Obj
CopyMemory Obj, 0&, 4
End Function