Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Const WM_CLOSE = &H10
In una normale routine di evento,come button
Dim winHwnd As Long Dim RetVal As Long winHwnd = FindWindow(vbNullString, "Internet Explorer") If winHwnd <> 0 Then RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&) If RetVal = 0 Then MsgBox "Errore nella chiusura." End If Else MsgBox "Internet non è aperto." End If
Questo codice é molto bello perchè per chiudere l'applicazione basta scrivere il suo nome!!!
Aggiungi un commento