I need to close my browser from my VB application. I tried using the CloseHandle API but it doesnt work. How do I make it work?
Thanx in advance for the time and effort spent,
Ramya.
Printable View
I need to close my browser from my VB application. I tried using the CloseHandle API but it doesnt work. How do I make it work?
Thanx in advance for the time and effort spent,
Ramya.
You have to get the window of the handle of your browser then close it.
Put this code in a module :
Option Explicit
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
This code in a button or form load :
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "Your browser Window Name")
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
MsgBox "Cannot close this Window"
End If
Else
MsgBox "Your Browser isn't open"
End If