I have the need to monitor an application and do something if the
application pops a message box up.
I'd like to be able to compare the text in the messagebox to some
predefined text strings and perhaps the title etc. and then trigger
some code.
I work in a laboratory that uses machines to test samples. Sometimes
the machine will break down and the PC controlling it pops up a
messagebox. The software will just sit there waiting for a human to
recify the problem. As the machines run overnight the problem wont be
found until the operators return the next morning. This could waste up
to 16 hours.
I'd like to trigger sending an email when this type of message box
pops up. I can easily send a message by instantiating an outlook
object, but its how to detect the messagebox and read its content that
illudes me.
It would be nice if the software vendor built this into their
application but this is never going to happen.
If anyone has any suggestions I would be most greatfull.
If I do write an app to achive this I will make it feely available on
my website.
TIA
>.
>
>.
>
But whether it's still available, no idea ...
"Andrew" <mez...@hotmail.com> wrote in message
news:a0155d0c.03072...@posting.google.com...
Hi, Andrew:
If you can pay the "performance penalty" (which doesn't seem to high,
anyway) you can modifiy the annexed function, that detects and logs changes
in the foreground window.
Perhaps you could send the e-mail notification, and do something with
keybd_event to close the messagge box and go on with your program until
somebody comes in.
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private lOrgWindow As Long
Public Sub DetectWindowChange()
Dim lWindow As Long
Dim sText As String
Dim sTime As Single
Dim f As Integer
lOrgWindow = GetForegroundWindow
sTime = Timer
Do While True
DoEvents
If Timer - sTime > 2.5 Then
lWindow = GetForegroundWindow
If lWindow <> lOrgWindow Then
lOrgWindow = lWindow
sText = Space(256)
GetWindowText lWindow, sText, 256
sText = Left(sText, InStr(sText, Chr(0)) - 1)
f = FreeFile
Open "C:\LOG.TXT" For Append As #f
Print #f, sText
Close f
sText = ""
End If
sTime = Timer
End If
Loop
End Sub
Good Luck!
Leonardo
[MS MVP - VB]
I'm guessing that as Windows is the OS, IT knows what's going on. The
only problem is hooking into Window's to see what's going on.
I'm thinking of it like AntiVirus software, it sits around and
monitors file Input/Output and does this or that depending on what it
finds.
Also there are apps you can get that monitor desktop activity, these
apps will log things like window title and even take a JPG screenshot
at intervals.
On this basis it seems perfectly feasable to have an app that trigers
some code when it sees a messagebox appear that contains "Critical
error" or whatever.
There are loads of programs that LOG these events, I need one that
runs an external program instead of logging it. (or even both)
Any thoughts?
"Ben Taylor" <ben_ta...@yahoo.co.uk> wrote in message news:<089b01c3529a$4616dad0$a401...@phx.gbl>...
If you enable "Smart Move" for your mouse, it will cause the mouse to move
automatically to the default button on any Message Box which pops up. You
could then create a simple background program to cause the mouse to click
automatically every so often. If the mouse is simply on the desktop, this
mouse click will do nothing, but, if a message box pops up, the cursor will
move to the default button. Then, when the Timer event in your program
occurs, it will click the mouse.
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal
dx As Long, ByVal dy As Long, _
ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Private Sub Timer1_Timer()
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0&, 0&, cButt,
dwEI
End Sub
A very bizarre solution, I know, but perhaps it will work.....
--
Dan
"Andrew" <mez...@hotmail.com> wrote in message
news:a0155d0c.03072...@posting.google.com...
You could have your app install a system-wide hook (SetWindowsHookEx)
that monitors the creation/display of all dialogs (classname "#32770")
windows. If the new window's process ID matches that of the other app,
it's a msgbox. That's assuming of course that the lame-o app doesn't
show other dialogs while unattended. If it does, it wouldn't be to
difficult to filter them out. Then it would just be a matter using
SendDlgItemMessage to send the appropriate button a BM_CLICK message
to dismiss the msgbox. You could also grab the msgbox title and text
to log it and/or analyze the nature of the alert and determine which
button to click. I'd probably use a system-wide WH_CBT type hook. It
would require an assist from a standard (C), but there are a number of
good freebies available, including one at http://www.mentalis.org/ .
I'd suggest downloading it and playing with some of the examples to
get an idea of what's possible.
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)