Punkt 1: Lustig :-|
Punkt 2: Nun ja...
Ich hab mir über API (! , ja, keine direkte "Listener-API" aber nahe dran) inzwischen ein Programm gebastelt, welches die gewünschte Funktionalität aufweist. Die verkürzte Form sieht folgendermaßen aus:
Public Class Form1
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long _
) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hwndParent As Long, _
ByVal hwndChildAfter As Long, _
ByVal lpszClass As String, _
ByVal lpszCaption As String _
) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As IntPtr, _
ByVal uMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32
Private WM_NCDESTROY As Integer = &H82
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Start()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
MsgBox(1, MsgBoxStyle.Question, "h")
'MessageBox.Show("s", "d", MessageBoxButtons.YesNo)
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles Timer1.Tick
Dim dlghWnd As Long
Dim lpString As String 'owners caption
Dim lhwnd As Long
Dim hWndOwner As Long
While lpString <> "Form1" 'owners caption
lpString = Space(255)
dlghWnd = FindWindowEx(0&, lhwnd, "#32770", vbNullString) 'Suchen
' nach Fenster mit MsgBox-Handle
If dlghWnd = 0 Then Exit Sub
hWndOwner = GetParent(dlghWnd) 'Handle der Owner-Form bestimmen
GetWindowText(hWndOwner, lpString, 255&) 'Titel der Owner-Form
' bestimmen
lpString = Mid(lpString, 1, InStr(lpString, Chr(0)) - 1) 'Titel
' der Owner-Form zurechtschneiden
lhwnd = dlghWnd
End While
dlghWnd = SendMessage(lhwnd, WM_NCDESTROY, 0, 0) 'MsgBox schließen
End Sub
End Class Wenn auf Button1 geklickt wird, fängt Timer1 die MsgBox automatisch ab und schließt sie.
Prinzipiell löst das mein Problem wahrscheinlich schon, ich bin halt nur nicht sicher ob der Timer im Hintergrund zuviel Ressourcen frisst, sodass meine (teils recht aufwändigen) Berechnungen dadurch performancemäßig beeinflusst werden. |