Stopping programs from running 
Author Message
 Stopping programs from running

I am creating a browser based on the IE4 WebBrowser control. I have
disabled the context-menus (right click popups) so that anyone using it
cannot open up a new window. I would like to be able to prevent any
other windows from popping up on their own. Fortunately for me as a
programmer, it is not my application that pops up, but Internet
Explorer, so I always know that I need to close a window that has that
caption in it. However, when I try to do this, it ends up closing my
window on load instead of MSIE, even when MSIE is loaded, or isn't
loaded.
Every time I perform an operation, I run KillApp("Microsoft Internet
Explorer")
Which runs through a list of the windows open, compares the caption, and
supposedly will kill the window that has the matching caption.
Unfortunately, it must either automatically close the last window, or it
closes a window with no caption... because my program never finishes
loading - it gets killed, apparently, by its own code.

This is the KillApp code (which I took and modified from one of the VB
sites - sorry, don't remember which one. This is all in a module
attatched to my project):

===========Begin Code Snippet===========

Option Explicit
DefInt A-Z

Declare Function FindWindowA Lib "User32" (ByVal Class&, ByVal Caption&)

Declare Function GetWindow Lib "User32" (ByVal hWnd, ByVal wCmd)
Declare Function GetNextQueueWindow Lib "User32" (ByVal hWnd, ByVal
wCmd)
Declare Function GetWindowTextA Lib "User32" (ByVal hWnd, ByVal Buf$,
ByVal lBuf)
Declare Sub ShowWindow Lib "User32" (ByVal hWnd, ByVal nCmd)
Declare Function SendMessageA Lib "User32" (ByVal hWnd As Integer, ByVal
wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Any) As Long

Const WM_CLOSE = &H10
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2

Function GetWinCaption$(hWnd)

    Dim strCaption As String * 256
    Dim NumChars

    NumChars = GetWindowTextA(hWnd, strCaption, 256)
    GetWinCaption$ = Left$(strCaption, NumChars)

End Function

'
' This program checks all the application windows' captions, if there is

' a match, it will ask the user to teminate the program or not.
' If there is nothing matches, it will terminate itself.
'
' This is useful when the user running an application and try to install

' it while it is running.
'
' Copyright 1997 (c) 2Link Consulting Inc.
' By Raymond Tsang
'
Public Function KillApp(AppCaption As String)

    Dim Wnd, lResult As Long, iResult

    Wnd = SearchWindow(AppCaption)
    If Wnd <> 0 Then
        lResult = SendMessageA(Wnd, WM_CLOSE, 0, 0&)
        End
    End If

End Function

Function SearchWindow(ByVal strSearch$)

    Dim hWnd

    ' Find the first window's handle
    hWnd = FindWindowA(0, 0)
    hWnd = GetWindow(hWnd, GW_HWNDFIRST)

    ' Set all comparison to upper case
    strSearch$ = UCase$(strSearch$)

    ' Start the loop for all windows
    Do While hWnd <> 0

        ' If the searching caption is a sub string of the current
window's caption
        If InStr(UCase$(GetWinCaption(hWnd)), strSearch$) Then
            ' Return the window's handle
            SearchWindow = hWnd
            Exit Function
        End If
        ' Get the next window handle
        hWnd = GetNextQueueWindow(hWnd, GW_HWNDNEXT)
    Loop

End Function

============End Code Snippet============

Anyone see anything wrong?
Thanks,
Andy Bond



Sat, 13 Jan 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. My programs won't stop running!

2. How to know when a program stopped running

3. How do I stop a program from running??

4. Stopping startup folder programs from running

5. (VB5) how to stop window animation when i stop my program

6. Run and Wait a program inside a program

7. How To Run Another Program From Visual Basic Program

8. Running VB5 programs from CD without using a setup program

9. Problem running a program from within my program (winoldap not responding)

10. How do I make my VB program Run an external program

11. Run and Wait a program inside a program

12. Showing/Hiding running programs in the taskbar at run-time

 

 
Powered by phpBB® Forum Software