Results 1 to 7 of 7

Thread: Closing programs

  1. #1
    ricmitch_uk
    Guest

    Question

    How could I close a program throught the API. I need to find a way of closing explorer running some code and then reloading explorer, without leaving Windows (if you know what I mean).

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    You can close a window using the DestroyWindow API Function.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    ricmitch_uk
    Guest
    Thanks. Will I be able to start explorer by using:
    shell strWinDir + "\explorer.exe"
    even if Explorer is closed? doesn't explorer have to be open to run programs using shell?

  4. #4
    Megatron
    Guest
    Vlatko DestroyWindow will close a window, but it will not end the process. You need to send the WM_QUINT message to do this.
    Code:
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Const WM_QUIT = &H12
    
    Private sub Command1_Click()
        PostMessage hwnd_of_window, WM_QUIT, 0, 0
    End Sub

  5. #5
    ricmitch_uk
    Guest
    Thanx but, how do I get the handle for a program?

  6. #6
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Code:
    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Sub Command1_Click()
        Dim hWnd As Long
        hWnd = FindWindow("NotePad", vbNullString)  'Here, you can supply the class name or the window caption
    End Sub

  7. #7
    Megatron
    Guest
    And to get the Classname for a window, you'd use a Spy tool such as Spy++.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width