Link to home
Start Free TrialLog in
Avatar of darbid73
darbid73Flag for Germany

asked on

Help with WinAPI Signatures in VB.NET for SetWindowSubclass

I am having trouble setting up the signatures to subclass a window in VB.NET

<DllImport("comctl32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
        Public Shared Function SetWindowSubclass(ByVal hWnd As IntPtr, ByVal pfnSubclass As WndProcDelegate, ByVal uIdSubclass As IntPtr, ByVal dwRefData As IntPtr) As IntPtr
        End Function

        <DllImport("comctl32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
        Public Shared Function GetWindowSubclass(ByVal hWnd As IntPtr, ByVal pfnSubclass As IntPtr, ByVal uIdSubclass As IntPtr, _
           pdwRefData As IntPtr) As IntPtr
        End Function

        <DllImport("comctl32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
        Public Shared Function RemoveWindowSubclass(ByVal hWnd As IntPtr, ByVal pfnSubclass As WndProcDelegate, ByVal uIdSubclass As IntPtr) As IntPtr
        End Function

        <DllImport("comctl32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
        Public Shared Function DefSubclassProc(ByVal hWnd As IntPtr, ByVal uMsg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
        End Function


        Public Delegate Function WndProcDelegate(ByVal hWnd As IntPtr, ByVal msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr, ByVal dwRefData As IntPtr) As IntPtr

Open in new window


Then how do I call the SetWindowSubclass - in particular how do I pass in the dwRefData as the last parameter?

SetWindowSubclass(aHwnd, AddressOf WndProc, New IntPtr(10), "WHAT GOES HERE")

Open in new window


Finally my callback looks like this
Public Function WndProc(ByVal hWnd As IntPtr, ByVal msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr, ByVal dwRefData As IntPtr) As IntPtr

            Select Case msg

                Case WM_NCDESTROY
                    Diagnostics.Debug.Print("######")
                    StopListener(hWnd)

            End Select

            'Diagnostics.Debug.Print(msg.ToString)

            WndProc = NativeMethods.DefSubclassProc(hWnd, msg, wParam, lParam)
        End Function

Open in new window


I normally use pinvoke.net but it does not seem to have these.
ASKER CERTIFIED SOLUTION
Avatar of darbid73
darbid73
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of darbid73

ASKER

Answered my own question