Check if Msgbox on screen?

Is there a way to either check if a MsgBox is on screen, OR, check if more than 1 window (the main window) is open?

I have my main window containing a ListBox, and I want to prevent the contextual menu from showing if any MsgBoxes or other windows are open. I have no idea how to check if any other windows or MsgBoxes are being displayed however :frowning:

I am thinking along the lines of setting the text of a hidden label to true whenever a MsgBox is called, or when a window is opened - and then check the text of the label in the contextual menu action.

Would that be a viable solution?

Any help would be gratefully appreciated.

Thank you all in advance.

A MsgBox is modal, so no other part of your application will react to mouse clicks.

For regular windows use the WindowCount and Window methods:

For i As Integer = 0 To WindowCount - 1 If Window(i) IsA MyWindow And Window(i).Visible Then // at least one instance of MyWindow is open and visible End Next

Thanks, but the ContextualMenu in the ListBox in the main window does still show if the user right-clicks over it, - even if a msgbox is currently displayed.

Left-clicks do not work - but the right-click still work :frowning:

Which OS?

Windows 8.1

At the moment I’m working on OS X, so I can’t help further - but it seems indeed strange that a application modal message box allows something like that.


Thank you anyway.


I’m running windows 8.1 and don’t see this behavior. None of my right-click contextual menus will work if a msgbox is being displayed. Do you have an example project you can post?



Unfortunately I can’t send it as it contains confidential information and I would get in trouble.

In cases like this, create a small project that replicates the issue. That you can share and will go a long way to replicating the issue and getting it fixed. Until that happens all we can go on is that you have a problem but no one else can do it.

I’ve seen it happen, a lot, where in the process of making a very simple project to show others you discover the real issue. This happens to me all the time. Sometimes you’ll discover a true framework bug but most of the time you’ll find it in your own code.

I have just noticed that if the MsgBox originates from the same window - the right-click DOES NOT work (as expected).
BUT, if the MsgBox originates from window 2, the user can move the mouse over Window 1, and still use the right-click of that window.

Hope that makes more sense.

I reproduced this MsgBox behavior with multiple windows on Windows 8.1. This seems like a bug. I’ve created feedback://showreport?report_id=32426.

In the meantime, try using MessageDialog instead of MsgBox.

Thanks guys - much appreciated.

What does that even mean? Modal is per-window, not applicable to the entire app.

I agree with Tim. A your contextual menus will work in the app so long as they are not on the window from which the msg box was initiated.

Well, this varies greatly depending on the platform and the technique you use.

Generally, modal ought to be app-specific unless you clearly state you want window-specific.

What I meant was - if an action on window 2 initiates a MsgBox , the user can still use the contextual menu of window 1. This is what I am trying to prevent.

Seems like it’s always been window-specific in REALbasic on Windows. Maybe it’s always been wrong? I’m just used to it, so I assumed that’s the way it’s supposed to be.