I apologize for the repost but I am frustrated and desperate for a
solution.
I need to detect if an external application is displaying a modal form.
I.E. dialog box or error message.
I found a number of promising examples but unfortunetly they are VB6
examples and just don't seem to be working correctly:
---------------Start Code------------------------------------
Private Declare Function apiGetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal Hwnd As Long, ByVal _
nIndex As Long) As Long
Function IsModal(ByVal hWndFrm As Long) As Boolean
Dim hWndParent As Long
Dim wStyle As Long
Const GW_STYLE = (-16)
Const WS_DISABLED = &H8000000
Const GW_HWNDPARENT = (-8)
hWndParent = apiGetWindowLong(hWndFrm, GW_HWNDPARENT)
If hWndParent = 0 Then
IsModal = False
Else
wStyle = apiGetWindowLong(hWndParent, GW_STYLE)
IsModal = ((wStyle And WS_DISABLED) <> 0)
End If
End Function
---------------End Code------------------------------------
Then I run the following on a timer:
---------------Start Code------------------------------------
Dim MonitoredProcess As Process() =
Process.GetProcessesByName("BuggyThirdPartyApp")
IsModal(MonitoredProcess (0).MainWindowHandle)
---------------End Code------------------------------------
It always returns false even if a modal is up.
The apiGetWindowLong(hWndFrm, GW_HWNDPARENT) always returns zero.
Thanks for your help!
Jeremy