Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close App

Status
Not open for further replies.

SpiderBear6

Programmer
Sep 17, 2003
422
AU
Here's an interesting problem.

I need to be able to identify and close certain applications. I know for VB6 apps I can use the FindWindow API with the ThunderRTMain parameter, but I am not going to know what the applications I need to close are written in. For example, one of the applications I need to close is written in C++.


--------------------------------------
"We are star-stuff. We are the universe made manifest trying to figure itself out."
-- Delenn in Babylon 5 - "A Distant Star"
 
No matter what the program is written in, can't you send the same message to your desired applications that windows sends when you do a Shutdown?
 
Usually I would run this code...

Code:
Public Function CloseApp(ByVal sClassName As String, ByVal sAppTitle As String) As Boolean
    Dim lRet As Long, Hwnd As Long, lPID As Long

    Hwnd = apiFindWindow(sClassName, sAppTitle)
    If (Hwnd) Then
        lRet = apiPostMessage(Hwnd, WM_CLOSE, 0, ByVal 0&)
        Call apiGetWindowThreadProcessId(Hwnd, lPID)
        Call apiWaitForSingleObject(lPID, INFINITE)
        CloseApp = Not (apiIsWindow(Hwnd) = 0)
    End If
End Function

and provide ThunderRT6Main (for VB6 apps) as the sClassName parameter and the app title as the sAppTitle parameter.




--------------------------------------
"We are star-stuff. We are the universe made manifest trying to figure itself out."
-- Delenn in Babylon 5 - "A Distant Star"
 
What happens if you don't know the value of the "cClassName" parameter?
 
Exactly my point... but I found out that you don't need it. You can just use the app title. But it's a bit risker.

--------------------------------------
"We are star-stuff. We are the universe made manifest trying to figure itself out."
-- Delenn in Babylon 5 - "A Distant Star"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top