Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Shared m_handle As IntPtr
- Private Shared m_hook As Interop.HwndSourceHook
- Private Shared m_hookCreated As Boolean = False
- 'Call on application start
- Public Shared Sub SetWindowHook(ByVal visualSource As Visual)
- 'Add in a Win32 hook to stop the browser app from loading
- If Not m_hookCreated Then
- m_handle = DirectCast(PresentationSource.FromVisual(visualSource), Interop.HwndSource).Handle
- m_hook = New Interop.HwndSourceHook(AddressOf WindowProc)
- Interop.HwndSource.FromHwnd(m_handle).AddHook(m_hook)
- m_hookCreated = True
- End If
- End Sub
- 'Call on application exit
- Public Shared Sub RemoveWindowHook()
- 'Remove the win32 hook
- If m_hookCreated AndAlso Not m_hook Is Nothing Then
- If Not Interop.HwndSource.FromHwnd(m_handle) Is Nothing Then
- Interop.HwndSource.FromHwnd(m_handle).RemoveHook(m_hook)
- End If
- m_hook = Nothing
- m_handle = IntPtr.Zero
- End If
- End Sub
- 'Intercept key presses
- Private Shared Function WindowProc(ByVal hwnd As System.IntPtr, ByVal msg As Integer, ByVal wParam As System.IntPtr, ByVal lParam As System.IntPtr, ByRef handled As Boolean) As System.IntPtr
- 'Stop the OS from handling help
- If msg = WM_HELP Then
- handled = True
- End If
- Return IntPtr.Zero
- End Function
Add Comment
Please, Sign In to add comment