I.E. 5.0 Windows Won't Close with VB6 API Code 
Author Message
 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).



Fri, 08 Mar 2002 03:00:00 GMT  
 I.E. 5.0 Windows Won't Close with VB6 API Code
Hi Lila,

First of all, does FindWindow() return a valid hWnd ?
If not, the rest of your code is quite useless.

I wouldn't use SendMessage() for this, try to use SendMessageTimeout()
instead, as your call to SendMessage() with WM_CLOSE specified might not
return to you.
SendMessageTimeout() let's you specify some time slice after which it will
return even if there wasn't any responce.

You should also check if the window still exists before sending a WM_DESTROY
(and use SendMessageTimeout() or PostMessage() here too).

I can't guarantee you this will work, but you should give it a try :-)

--
Hope this helps ...

Rene Whitworth
Whitworth Software Solutions - Germany
http://www.w-s-s.de
Please reply to the newsgroup :-)



Quote:
> 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://wfox.onradio.com/script/stream"
_
>       & "_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://wfox.onradio.com/script/" _
>                              & "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.dekalb.k12.ga.us/~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).



Fri, 08 Mar 2002 03:00:00 GMT  
 I.E. 5.0 Windows Won't Close with VB6 API Code
Lila...

Quote:
> In my VB6 SP3 project I have the following (more code present, but not
> listed here)

Explorer windows are a bit more stubborn than others... Try sending a
WM_SYSCOMMAND message with SC_CLOSE as the wParam... this works for me.

--
Ben Baird, MVP
Visual Basic Thunder
http://www.vbthunder.com
Please keep your programming questions on the newsgroups.



Fri, 08 Mar 2002 03:00:00 GMT  
 I.E. 5.0 Windows Won't Close with VB6 API Code

Quote:
> In my VB6 SP3 project I have the following (more code present, but not
> listed here)
> 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.

Update -

Use of WM_SYSCOMMAND message with SC_CLOSE as the wParam (suggested here)
and new code from MSDN online did not work.  After implementing the MSDN
code I realized the first browser was opening after the issuance of the
close code (My load code does not make use of shell and wait code.).  I also
realized the second window was not loading right away.  This would cause
problems if the first Window was closed immediately after being loaded.

The solution was to include the close function call in a loop with a
BrowserHandle = 0 test and add sleep code. The new Form Load code is as
follows:

BrowserCaption =
"javascript:void(window.open('http://wfox.onradio.com/script/" _
               & "stream_player2_5.html','_newwindow', - Microsoft Internet
" _
               & "Explorer"
Dim Y As Integer
Do Until BrowserHandle <> 0
   Sleep (1000) 'api call wait for 1st window to load and load 2nd window
   BrowserHandle = FindWindow(vbNullString, BrowserCaption)
Loop
Y = EndTask(BrowserHandle) 'EndTask is revised function from MSDN site
                                                    'code to prevent closing
of program doing close
                                                    'detected hWnd was for
VB app also web
                                                    'page had 16 bit
declares above function
If Y = 0 Then
   MsgBox "Error - Cannot terminate " & BrowserCaption
   Unload Me
End If
Unload Me



Fri, 08 Mar 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. API code won't close Access instance

2. ActiveX DLL won't close from IE

3. IE window won't close politely

4. Custom ActiveX control won't show in IE browser under Windows 95 on other computers

5. Why windows won't close after shell process

6. Ctrl-F4 won't close child windows in VB5 with some controls

7. Access97 won't close after running DAO code

8. creating windows using win'95 api...

9. creating windows using win'95 api...

10. creating windows using win'95 api...

11. EM_GETSEL won't work with VB3 code windows (class OModule)

12. vb6 installer won't work with windows 2000

 

 
Powered by phpBB® Forum Software