All pastes #436574 Raw Edit

Untitled

public text v1 · immutable
·published 2007-04-12 16:29 UTC
rendered paste body
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim z() As Integer = FindWindowLike(GetDesktopWindow, "clients_*", "Afx:400000*")
        z = FindWindowLike(GetDesktopWindow, "Untitled*", "Notepad")

        FMHwnd = New IntPtr(z(1))

        OldWindowProc = SetWindowLong(FMHwnd, GWL_WNDPROC, Me.myCallback)


    End Sub
    Dim OldWindowProc As IntPtr
    Dim FMHwnd As IntPtr
    Delegate Function SubclassCallback(ByVal hWnd As IntPtr, ByVal Msg As IntPtr, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
             (ByVal hWnd As IntPtr, ByVal nIndex As IntPtr, ByVal dwNewLong As SubclassCallback) As IntPtr
    'Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    '       (ByVal hWnd As IntPtr, ByVal nIndex As IntPtr, ByVal dwNewLong As IntPtr) As IntPtr
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
            (ByVal lpPrevWndFunc As IntPtr, ByVal hWnd As IntPtr, ByVal Msg As IntPtr, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    Private GWL_WNDPROC As IntPtr = New IntPtr((-4))
    Private prevHandle As IntPtr
    Private myCallback As New SubclassCallback(AddressOf Me.SubclassCallbackHandler)

    Private Function SubclassCallbackHandler(ByVal hWnd As IntPtr, ByVal Msg As IntPtr, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

        ' Process whatever messages you want here

        ' NOTE : THIS IS VERY IMPORTANT ! FORWARD MESSAGE TO ORIGINAL HANDLE
        Return CallWindowProc(Me.prevHandle, hWnd, Msg, wParam, lParam)


    End Function