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?
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.
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.
Last edited by Edgemeal; May 29th, 2008 at 12:24 PM.
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?
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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?
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.