vb6: how to run a program from vb6 and close it once it finishes?

后端 未结 2 1095
误落风尘
误落风尘 2021-01-21 06:52

basically vb6 launches a process but the problem is closing it when it finishes.

shell \"something.exe\"

when the external program displays msg

2条回答
  •  半阙折子戏
    2021-01-21 07:09

    If you know the title or class name of the program, then you can use FindWindow and PostMessage API calls to close it.

    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 
    
    Dim hwnd As Long
    hwnd = FindWindow(vbNullString, "WINDOW CAPTION HERE")
    PostMessage hwnd, WM_CLOSE, CLng(0), CLng(0) 
    

提交回复
热议问题