Is there a way to determine if a msgbox is open?
Im using keyboard hooks for some shortcuts that are application-wide and so far everything is working fine, but some short-cuts load non-modal forms and if a user presses a short-cut key while a MsgBox is up, the form loads and it looks kind of silly, or in some instances out right locks up the software.
Is there a way to determine (either through VB6 or an API) if a Messagebox, or any other dialog box is open so that I can ignore my hooks at that time?
Thank you,
Luke
Re: Is there a way to determine if a msgbox is open?
Assuming the messageboxs are the result of your code, you could create a public boolean which would be set to true just before any msgbox call you make, and reset to false immediately thereafter.
If the boolean is true, then ignore the hooks.
Re: Is there a way to determine if a msgbox is open?
Thats my last resort as there are a lot of forms, I was hoping to do it all in one place as opposed to form by form.
Re: Is there a way to determine if a msgbox is open?
Couldn't you make a public function and pass it the text string, etc, and set a public flag you can check in the keyboard hook? Maybe something like,
Code:
Option Explicit
Public MsgBoxOpen As Boolean
Public Function MyMsgbox(Stxt As String, flags As Long)
MsgBoxOpen = True
MsgBox Stxt, flags
MsgBoxOpen = False
End Function
Sub KeyBoardHook()
If MsgBoxOpen = True Then Exit Sub
' else watch keys...
End Sub
If that would work you could just use the VB find and replace and change all MsgBox commands to MyMsgBox.
Re: Is there a way to determine if a msgbox is open?
That would work, but this is a large project with a few developers, so replacing all existing code, plus asking all future dev. to use a custom msgbox function probably wont work.
Could I hook in and listen for a window create message, and somehow determine from that if its a message box?
1 Attachment(s)
Re: Is there a way to determine if a msgbox is open?
I'm no pro when it comes to hooks but this might help give you some ideas...
Re: Is there a way to determine if a msgbox is open?
What about doing a FindWindow on the #32770 class type (dialog) and checking the owner of the window to see if its your app. If it is then you have a msgbox open. If its not then move on to the next window and if none are found then your app doesnt have a msgbox open.
Re: Is there a way to determine if a msgbox is open?
Thanks that works pretty well, and almost exactly what I need, except it looks for Activate, and when I set to HCBT_CREATEWND, it didnt trigger it.
I think I got a different way of doing it though, I get all Window Hwnds through
GetWindowThreadProcessId, and then determine if the Window class is of Dialog type, so far so good.
Re: Is there a way to determine if a msgbox is open?
Quote:
Originally Posted by RobDog888
What about doing a FindWindow on the #32770 class type (dialog) and checking the owner of the window to see if its your app. If it is then you have a msgbox open. If its not then move on to the next window and if none are found then your app doesnt have a msgbox open.
Heh, posted at the same time, exactly what Im trying right now. :thumb:
Re: Is there a way to determine if a msgbox is open?
Great minds think alike. :)