1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
Option Explicit
'////////////////////////////////////////////////////////////////////////////////////////////////////
Const WM_APP As Long = 32768
Private Const GWL_WNDPROC = (-4)
Private procOld As Long
Private Declare Function CallWindowProc Lib "USER32.DLL" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "USER32.DLL" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Sub CopyMemory Lib "KERNEL32.DLL" Alias "RtlMoveMemory" _
(ByVal pDst As Long, ByVal pSrc As Long, ByVal ByteLen As Integer)
Private Declare Sub ZeroMemory Lib "KERNEL32.DLL" Alias "RtlZeroMemory" _
(ByVal pDst As Long, ByVal ByteLen As Integer)
Public Sub SubclassWindow(ByVal hWnd As Long)
procOld = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf SubWndProc)
End Sub
Public Sub UnsubclassWindow(ByVal hWnd As Long)
procOld = SetWindowLong(hWnd, GWL_WNDPROC, procOld)
End Sub
Private Function SubWndProc( _
ByVal hWnd As Long, _
ByVal iMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long, ByVal retour As String) As Long
If hWnd = Form1.hWnd Then
If iMsg = WM_APP Then
'Dim inf As TestInfo
' Copy First Field (label)
'Call CopyMemory(VarPtr(inf), lParam, 4)
' Copy Second Field (count)
'Call CopyMemory(VarPtr(inf) + 4, lParam + 4, 4)
Dim strInfo As String
strInfo = retour
Call MsgBox(strInfo, vbOKOnly, "WM_APP Received!")
' Clear the First Field (label) because it is a string
'Call ZeroMemory(VarPtr(inf), 4)
' Do not have to clear the 2nd field because it is an integer
SubWndProc = True
Exit Function
End If
End If
SubWndProc = CallWindowProc(procOld, hWnd, iMsg, wParam, lParam, retour)
End Function
'///////////////////////////////////////////////////////////////////
Private Sub Command1_Click()
Dim aClass As Class1
Set aClass = New TestInterOP.Class1
aClass.Test Me.hWnd
End Sub |
Partager