Option Explicit
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hWnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As _ Any) As Long 'Private Const WM_CLEAR = &H303 Private Const WM_CLOSE = &H10 Private Sub Command1_Click() Timer1.Enabled = True MessageBox hWnd, "Ciao", "MsgBox a Tempo", vbInformation Timer1.Enabled = False End Sub Private Sub Timer1_Timer() Dim hWnd As Long hWnd = FindWindow(vbNullString, "MsgBox a Tempo") If hWnd Then SendMessage hWnd, WM_CLOSE, 0, 0 End If End Sub |