Public Class Form1
Private Const GWL_WNDPROC = -4
Private Declare Function GetWindowLong Lib "user32.dll" _
Alias "GetWindowLongA" (
ByVal hwnd As Integer,
ByVal nIndex As Integer) As Integer
Private Declare Function SetWindowLong Lib "user32.dll" _
Alias "SetWindowLongA" (
ByVal hwnd As Integer,
ByVal nIndex As Integer,
ByVal dwNewLong As Integer) As Integer
Private Declare Function SetWindowLong Lib "user32.dll" _
Alias "SetWindowLongA" (
ByVal hwnd As Integer,
ByVal nIndex As Integer,
ByVal dwNewLong As D_MyWndProc) As Integer
Private Declare Function CallWindowProc Lib "user32.dll" _
Alias "CallWindowProcA" (
ByVal lpPrevWndFunc As Integer,
ByVal hwnd As Integer,
ByVal msg As Integer,
ByVal wParam As Integer,
ByVal lParam As Integer) As Integer
Private Declare Function SendMessage Lib "user32.dll" _
Alias "SendMessageA" (
ByVal hwnd As Integer,
ByVal msg As Integer,
ByVal wParam As Integer,
ByVal lParam As Integer) As Integer
Private lngWnP As Integer
Private Delegate Function D_MyWndProc(
ByVal hwnd As Integer,
ByVal msg As Integer,
ByVal wParam As Integer,
ByVal lParam As Integer) As Integer
Private DgWndProc As D_MyWndProc = Nothing
Private Sub Form1_Load(
ByVal sender As System.Object,
ByVal e As System.EventArgs) _
Handles MyBase.Load
lngWnP = GetWindowLong(Me.Handle, GWL_WNDPROC)
DgWndProc = AddressOf MyWndProc
Call SetWindowLong(
Me.Handle, GWL_WNDPROC, DgWndProc)
End Sub
Private Sub Form1_FormClosed(
ByVal sender As System.Object,
ByVal e As System.Windows.Forms.FormClosedEventArgs) _
Handles MyBase.FormClosed
Call SetWindowLong(Me.Handle, GWL_WNDPROC, lngWnP)
End Sub
Private Sub Timer1_Tick(
ByVal sender As System.Object,
ByVal e As System.EventArgs) _
Handles Timer1.Tick
SendMessage(Me.Handle, 9999, 0, 0)
End Sub
Private Function MyWndProc(
ByVal hwnd As Integer,
ByVal msg As Integer,
ByVal wParam As Integer,
ByVal lParam As Integer) As Integer
Select Case msg
Case 9999
System.Diagnostics.Debug.WriteLine(
Now & "メッセージを受信しました")
End Select
Return CallWindowProc(lngWnP, hwnd, msg, wParam, lParam)
End Function
End Class