I'm trying to verify that a program is still running, by getting the enabled status of a menu item. If it's disabled, the app is running, if it's enabled, then the app has stopped. Simple enough right?
Please help! This is what I have tried:
Or should I try to use the MF_DISABLED constant with something?Code:Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Integer) As Integer Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer Private Declare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Integer) As Integer If FindWindow(vbNullString, "AppTitle") <> 0 Then Dim hMenu, hSubMenu As Integer hMenu = GetMenu(FindWindow(vbNullString, "AppTitle")) hSubMenu = GetSubMenu(hMenu, 0) If IsWindowEnabled(hSubMenu) Then MessageBox.Show("App not running") Else MessageBox.Show("App running") End If Else MessageBox.Show("App, is closed") End If




Reply With Quote