Results 1 to 10 of 10

Thread: Api to shutt down prog

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2000
    Location
    Reykjavík, Iceland
    Posts
    29

    Api to shutt down prog

    Is there an api you could use to shut down program from another program?

    IceSoft

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Get the handle of the window that should be desroyed usinf FindWindow and then do
    VB Code:
    1. Declare Function DestroyWindow Lib "user32" Alias "DestroyWindow" (ByVal hwnd As Long) As Long
    2.  
    3. DestroyWindow hwndofthewindow

    or use SendMessage first send the WM_CLOSE then the WM_DESTROY messages.
    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
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    This has always worked for me.

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    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_CLOSE = &H10
    Private Const WM_QUIT = &H12

    Dim CloseIt As Long
    CloseIt = FindWindow(vbNullString, "Caption Of Window To Be Closed")
    PostMessage CloseIt, WM_CLOSE, CLng(0), CLng(0)

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2000
    Location
    Reykjavík, Iceland
    Posts
    29
    ok tanx allot.

    IceSoft

  5. #5
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276
    Hack,
    I have a similar requirement where I am using ShellExecute to open the regsvr32.exe to unregister Dlls. This leaves the Notification Messager Window open. I want to close this and proceed. I tried this code u posted. It works fine when I trace thru the program, bringing focus to the VB App. But When i let it run by itself, the Notification Window has focus and wouldn't let the code continue to close it. Have u any suggestions? Hope I have explained myself clear here. If not, pls verify with me.

    Thanks,
    Jemima.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Make your window the topmost window so it will always have focus regardless of what other windows are displayed.

  7. #7
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276
    how would I do that?

  8. #8
    Addicted Member Michael Woolsey's Avatar
    Join Date
    Nov 2000
    Location
    Calgary, Alberta, Canada.
    Posts
    243
    JemimaChadwick,

    Couldn't you just run regsvr32 with the /s option for silent running (no message boxes)?

    Michael
    Application/Web Developer

    Visual Basic 6.0 SP5
    Active Server Pages
    Oracle 9i
    - I'm going to live forever, or die trying!

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    JemimaChadwick:

    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

    Private Const SWP_NOMOVE = 2
    Private Const SWP_NOSIZE = 1
    Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2

    Private Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long
    On Error Goto ErrRtn
    If (Topmost) Then
    SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
    Else
    SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
    SetTopMostWindow = False
    End If
    Exit Function
    ErrRtn:
    MsgBox "Error in SetTopMostWindow " & Err & " " & Error, vbExclamation + vbOKCancel
    End Function

    'In Form Load Event, put...
    SetTopMostWindow Me.hwnd, TRUE

  10. #10
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276

    Done

    Thanks Michael. That did it.

    Thanks Hack. Michael's suggestion fixed the requirement. I tried this too. The window did remain on top always but the focus was transeferred to the called appln.

    Anyways, its done. Thanks.
    Sorry Icesoft for stealing ur space!
    -Jemima.

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