vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
sevDataGrid - Gönnen Sie Ihrem SQL-Kommando diesen krönenden Abschluß!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Fortgeschrittene
Re: ShellHook? 
Autor: Tortischlumpf
Datum: 08.08.06 08:23

' Folgender Code in ein Modul
' ---------------------------
 
Option Explicit
 
'Windows API
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
  (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, _
  ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
  ByVal lpProcName As String) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal _
  hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal _
  lpLibFileName As String) As Long
Declare Function RegisterWindowMessage Lib "user32" Alias _
  "RegisterWindowMessageA" (ByVal lpString As String) As Long
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
  (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal _
  dwThreadId As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal _
  hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
 
'Undocumented (at least that I could find) Windows API.
'  Use with caution
Declare Function RegisterShellHookWindow Lib "user32" (ByVal hWnd As _
  Long) As Long
 
'Constants for Windows API
Public Const HSHELL_WINDOWCREATED = 1
Public Const HSHELL_WINDOWDESTROYED = 2
Public Const HSHELL_ACTIVATESHELLWINDOW = 3
Public Const HSHELL_WINDOWACTIVATED = 4
Public Const HSHELL_GETMINRECT = 5
Public Const HSHELL_REDRAW = 6
Public Const HSHELL_TASKMAN = 7
Public Const HSHELL_LANGUAGE = 8
 
Public Const WM_NCDESTROY = &H82
 
Public Const GWL_WNDPROC = -4
 
Public Const WH_SHELL = 10
 
'Variables
Private lpPrevWndProc As Long ' Address of previos window proc
Private msgShellHook As Long  ' Msg number of "SHELLHOOK" message
 
'Start the subclassing of the window
Public Sub Hook(hWnd As Long)
  lpPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
 
'Stop the subclasing of the window
Public Sub Unhook(hWnd As Long)
  SetWindowLong hWnd, GWL_WNDPROC, lpPrevWndProc
End Sub
 
'Main Entry point.  Setup the system wide WH_SHELL hook, and start the
'  subclassing of the form to view messages.
Public Sub StartHook(hWnd As Long)
 
  'This is the message that Shell32's ShellHookProc sends us whenever
  '  a shell hook occurs
  msgShellHook = RegisterWindowMessage("SHELLHOOK")
 
  'Load the Shell32 library, and find the ShellHookProc so we can pass
  '  it to SetWindowsHookEx to create the Shell Hook
  Dim hLibShell As Long
  Dim lpHookProc As Long
 
  hLibShell = LoadLibrary("shell32.dll")
  lpHookProc = GetProcAddress(hLibShell, "ShellHookProc")
 
  'Initialize ShellHookProc
  RegisterShellHookWindow hWnd
 
  SetWindowsHookEx WH_SHELL, lpHookProc, hLibShell, 0
 
  'Start the subclassing of the window so we get the "SHELLHOOK" '
  '  messages generated from ShellHookProc
  Hook hWnd
 
End Sub
 
'Subclassing procedure, look for "SHELLHOOK" messages and process
Private Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, _
  ByVal wParam As Long, ByVal lParam As Long) As Long
 
  Select Case uMsg
    Case WM_NCDESTROY  'If we receive this message, unhook our subclassing
                       '  routing, to prevent crashing the app as it closes
      Unhook hWnd
    Case msgShellHook  'This is the message generated from Shell32's
                       '  ShellHookProc, decode it, and send the results
                       '  up to the From1's handlers
      Select Case wParam
        Case HSHELL_WINDOWCREATED
          ' Code wenn ein Fenster erstellt wurde
 
        Case HSHELL_WINDOWDESTROYED
          ' Code wenn ein Fenster zerstört wurde
 
        Case HSHELL_REDRAW
          ' Code wenn ein Fenster neu gezeichnet wird
 
        Case HSHELL_WINDOWACTIVATED
          ' Code wenn ein Fenster aktiviert wird
 
      End Select
  End Select
 
  WindowProc = CallWindowProc(lpPrevWndProc, hWnd, uMsg, wParam, lParam)
End Function
 
' ------------------
' End of module code
 
' Begin of Form-Code
' ---------------------------
Option Explicit
 
Private hWndOldActive As Long
 
'On form load, start the subclassing of the window,
'  as well as the shell hook
Private Sub Form_Load()
  StartHook Me.hWnd
End Sub
 
'On form exit, stop the subclassing
Private Sub Form_Unload(Cancel As Integer)
  Unhook Me.hWnd
End Sub
 
' End of form code
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
ShellHook?1.330Tortischlumpf07.08.06 09:30
Re: ShellHook?914ModeratorFZelle07.08.06 18:33
Re: ShellHook?977Tortischlumpf08.08.06 08:23
Re: ShellHook?1.464Tortischlumpf08.08.06 08:23

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel