Hallo,
habe nach längerer Suche ein Snippet gefunden, mit dem man herausfindet, wenn ein Fenster geöffnet wird, aktiviert wird etc pp.
habe nach längerer Suche ein Snippet gefunden, mit dem man herausfindet, wenn ein Fenster geöffnet wird, aktiviert wird etc pp.
VB.NET-Quellcode
- 'Credits: TreyJ
- Imports System.Runtime.InteropServices
- Public Class Form1
- ' Shell Events Constants
- Public Enum ShellEvents
- HSHELL_WINDOWCREATED = 1
- HSHELL_WINDOWDESTROYED = 2
- HSHELL_ACTIVATESHELLWINDOW = 3
- HSHELL_WINDOWACTIVATED = 4
- HSHELL_GETMINRECT = 5
- HSHELL_REDRAW = 6
- HSHELL_TASKMAN = 7
- HSHELL_LANGUAGE = 8
- HSHELL_ACCESSIBILITYSTATE = 11
- End Enum
- ' API Declares
- Public Declare Function RegisterWindowMessage Lib "user32.dll" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Integer
- Public Declare Function DeregisterShellHookWindow Lib "user32" (ByVal hWnd As IntPtr) As Integer
- Public Declare Function RegisterShellHookWindow Lib "user32" (ByVal hWnd As IntPtr) As Integer
- Private uMsgNotify As Integer
- Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Me.Text = Me.Handle
- ' This will register the ShellHook event messages between the shell and our application.
- ' The uMsgNotify is then used to communicate between the shell and our application whenever any
- ' of the shell events are fired such as an app starting up, shutting down, activating, minimizing, etc
- uMsgNotify = RegisterWindowMessage("SHELLHOOK")
- ' This basically registers our window to receive the shell events
- Call RegisterShellHookWindow(Me.Handle)
- End Sub
- Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- DeregisterShellHookWindow(Me.Handle)
- End Sub
- Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
- If m.Msg = uMsgNotify Then
- Select Case m.WParam.ToInt32
- Case ShellEvents.HSHELL_WINDOWACTIVATED 'Remove space after dot
- Debug.WriteLine("window activated: " & m.LParam.ToInt32)
- Case ShellEvents.HSHELL_WINDOWCREATED
- Debug.WriteLine("window created: " & m.LParam.ToInt32)
- '...
- End Select
- End If
- MyBase.WndProc(m)
- End Sub
- End Class
Für ein Mindestmaß an Rechtschreibung, Interpunktion und Majuskeln!