Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checking for a MsgBox

1 view
Skip to first unread message

gv...@my-deja.com

unread,
Aug 10, 2000, 3:00:00 AM8/10/00
to
I have an App which checks by the caption if a certain program is
running. And it works fine: if i want to check if Internet Explorer is
running I type "Explorer" in the Private Sub Command1_Click(), if I want
to check if Microsoft Word is running I type Word, and so on.
But unfortunately I can not check if a MsgBox is opened on the screen.
Could anyone tell me if I can easily change something in my App to do
this task, or do I have to start from the beginning.

I include the code also because someone else might need such an
application.

Take care of yourself,

Vio

--------
The code:


'---form code---

Private Sub Command1_Click()
Dim h As Long
Dim r
Debug.Print IsAppRunning("Explorer", h), h
If h > 0 Then
r = MsgBox(" Explorer is running")
End If
If h = 0 Then
r = MsgBox("Explorer is not running")
End If
End Sub


'---Bas module---

Private Declare Function FindWindow Lib "user32"
Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long
Private Declare Function GetWindow Lib "user32"
(ByVal hwnd As Long, ByVal wCmd As Long) 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 Declare Function GetParent Lib "user32"
(ByVal hwnd As Long) As Long

Public Const GW_HWNDNEXT = 2

Public Function IsAppRunning(TitlePart As String,
Optional AppHwnd As Long = 0) As Boolean
Dim h As Long, k As Long
Dim sName As String
h = FindWindow(vbNullString, vbNullString)
Do Until h = 0
If GetParent(h) = 0 Then
sName = Space(256)
k = GetWindowText(h, sName,
Len(sName))
If k > 0 Then
sName = UCase(Left(sName, k))
If InStr(sName, UCase(TitlePart))
Then
AppHwnd = h
IsAppRunning = True
Exit Do
End If
End If
End If
h = GetWindow(h, GW_HWNDNEXT)
Loop
End Function


Sent via Deja.com http://www.deja.com/
Before you buy.

Lieven Keersmaekers

unread,
Aug 10, 2000, 3:00:00 AM8/10/00
to
The findwindow returns only toplevel windows.
When you find a handle of a toplevel window, use this
in the EnumerateChildWindows callback procedure to
get all handles of all children. This way you should
be able to find your messagebox.


Juergen Thuemmler

unread,
Aug 11, 2000, 3:00:00 AM8/11/00
to

Lieven Keersmaekers <lieven.ke...@argenta.be> schrieb in im
Newsbeitrag: OqvdX3rAAHA.82@cppssbbsa04...
A messagebox is a toplevel window, but its class is "#32770"
like much other dialog windows, though you should know its caption
to be able to catch it by use of "FindWindow(...)".

Juergen.

0 new messages