
I.E. 5.0 Windows Won't Close with VB6 API Code
In my VB6 SP3 project I have the following (more code present, but not
listed here)
some code in Declares section for frmStartup
Dim Url As String
Dim BrowserCaption As String
Dim BrowserName As String
Dim BrowserHandle As Long
Const WM_CLOSE = &H10
Const WM_DESTROY = &H2
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As Any,
_
ByVal lpWindowName As Any) As Integer
Private Declare Function SendMessageA Lib "user32" (ByVal hwnd As Integer,
ByVal _
wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
Private Function KillWindow(hwnd&)
Dim Res& ' Ask it politely to close
Res = SendMessageA(hwnd, WM_CLOSE, 0, 0)
' Kill it (just in case)
'Res = SendMessageA(hWnd, WM_DESTROY, 0, 0)
End Function
some code from the Form_Load event
Url = "javascript:void(window.open(' http://www.*-*-*.com/ ; _
& "_player2_5.html','_newwindow','toolbar=no,location=no,status=" _
& "no,directories=no,menubar=no,scrolling=no,
scrollbars=no,width=446," _
& "height=274,resize=no'))"
BrowserCaption =
"javascript:void(window.open(' http://www.*-*-*.com/ ; _
& "stream_player2_5.html','_newwindow', -
Microsoft Internet " _
& "Explorer"
BrowserHandle = FindWindowA(vbNullString, BrowserCaption)
KillWindow (BrowserHandle)
Unload Me
When I run the program it correctly loads the url in the variable Url in an
I.E. 5.0 session generating the load of the desired popup window (done via
other Form_Load code not above). Once this is done the plain browser window
(not popup) does not close.
If I replace BrowserCaption in the second to last line above with
"Untitled - Notepad" and run the program after loading notepad the notepad
window closes. Issuing MsgBox (BrowserHandle) at the end yields a non zero
number. Using a browser caption of LHS Online - Microsoft Internet Explorer
(the caption of http://www.*-*-*.com/ ~lakeside/) does not close a
window pointed at that site.
The browse in a separate process option is on to prevent loss of systray
icons in crashes.
This applications is to allow me to get to radio station's live music with
one click on a shortcut (no clicking around their web site).