Results 1 to 10 of 10

Thread: Is there a way to determine if a msgbox is open?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    18

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    18

    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.

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    18

    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?

  6. #6
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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...
    Attached Files Attached Files

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    18

    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.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    18

    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.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Is there a way to determine if a msgbox is open?

    Great minds think alike.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width