Quote:
Originally Posted by FishVal
Hi, jercha.
If you will manage to run WinExplorer via "Shell" function, then the following will be useful for you
Close a Program
Your notepad program worked for notepad but not for explorer.
How do I fix?
I replaced notepad with explorer but the
CloseProcess failed to close the explorer screen:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hWnd As Long, ByRef lpdwProcessId As Long) As Long
Public Declare Function EnumWindows Lib "user32" _
(ByVal fpCallback As Long, ByVal lParam As Long) As Long
Public Const WM_CLOSE = 16
Public Sub RunAndCloseApp()
Dim lngProcID As Long
lngProcID = Shell("explorer")
MsgBox "Explorer started, Ok to close it", vbOKOnly, "Close App"
CloseProcess lngProcID
End Sub
Public Sub clbEnumWindows(ByVal hWnd As Long, ByVal lngParam As Long)
Dim lngProcID As Long
GetWindowThreadProcessId hWnd, lngProcID
If lngProcID = lngParam Then
'Debug.Print hWnd, lngProcID
SendMessage hWnd, WM_CLOSE, 0, 0
End If
End Sub
Public Sub CloseProcess(ByVal lngProcID)
EnumWindows AddressOf clbEnumWindows, lngProcID
End Sub