Closing Programs in VB 
Author Message
 Closing Programs in VB

Is there a way (API, VB function etc) that I can program to close all the
programs on the desktop?
Please be specific with links and functions.  Thanks


Mon, 08 Dec 2003 05:07:05 GMT  
 Closing Programs in VB
I am not going to be specific(lack of time),
but you can get all the handles of app's
then send them all the WM_CLOSE
message w/ SendMessage

Joseph


Quote:
> Is there a way (API, VB function etc) that I can program to close all the
> programs on the desktop?
> Please be specific with links and functions.  Thanks



Mon, 08 Dec 2003 05:13:04 GMT  
 Closing Programs in VB

Hi Jon.

The following code looks for windows that appear in the taskbar and posts a
WM_QUIT message to them. It assumes that it is running from a form and that
you don't want to close that form (this is the hWnd <> Me.hWnd check) but
you can remove that if you need to.

You're not supposed to post WM_QUIT messages and I guess posting WM_CLOSE
might have the same effect.

Anyway, hopefully this will give you a start from which to experiment.

Note: you'll need to import the appropriate API declare's and constants.

Dim hWnd As Long, dwStyle As Long, dwExStyle As Long
  hWnd = GetWindow(GetDesktopWindow(), GW_CHILD)
  While hWnd <> 0
    dwStyle = GetWindowLong(hWnd, GWL_STYLE)
    dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE)
    If ((GetWindow(hWnd, GW_OWNER) = 0 And (dwExStyle And WS_EX_TOOLWINDOW)
= 0) _
        Or (dwExStyle And WS_EX_APPWINDOW) = WS_EX_APPWINDOW) _
        And (dwStyle And WS_VISIBLE) <> 0 _
        And hWnd <> Me.hWnd Then
            PostMessage hWnd, WM_QUIT, 0, 0
    End If
    hWnd = GetWindow(hWnd, GW_HWNDNEXT)
  Wend

Hope this helps.

Best regards,

Ade.


Quote:
> Is there a way (API, VB function etc) that I can program to close all the
> programs on the desktop?
> Please be specific with links and functions.  Thanks



Mon, 08 Dec 2003 06:15:22 GMT  
 Closing Programs in VB


Quote:
> You're not supposed to post WM_QUIT messages and I
> guess posting WM_CLOSE might have the same effect.

Correct! Please use WM_CLOSE, not WM_QUIT. Only Windows should post this
message.


Wed, 10 Dec 2003 04:25:02 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Disable closing program in VB

2. Closing Programs in VB

3. Closing Programs in VB

4. How to close VB 4.0 16 bit program when a Crystal report Window is closed

5. closing VB-program with VBA

6. VB closing an external program using an API function

7. Closing an application through V.B. (how to find program names)

8. How to close a program from my VB application

9. VB.Net - Closing first form exits program?

10. How to wait for an external program to close before running my VB app

11. newbie question about closing VB programs

12. VB newbie! Close Program after specified time

 

 
Powered by phpBB® Forum Software