Results 1 to 18 of 18

Thread: Is this form modal?

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Is this form modal?

    Is there anyway to tell if a particular form is modal or modeless?

    Is there a property of the form I can check? Or perhaps some other way?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

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

    Re: Is this form modal?

    The window style for the form being shown vbModeless will have a window style of WS_EX_APPWINDOW. For a Modal form its style will not have that style applied.
    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

  3. #3

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Is this form modal?

    Do you know how to interrogate a form's window style? Presumably by some API call?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Is this form modal?

    Rob, is there any way you have found that you can apply that style to a window thus making it a modal form over another window/form (preferably external window)? I'm probably asking for too much


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Is this form modal?

    Quote Originally Posted by simonm
    Do you know how to interrogate a form's window style? Presumably by some API call?
    I think it's the GetWindowLong you need.


    Has someone helped you? Then you can Rate their helpful post.

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

    Re: Is this form modal?

    I used MS Spy++ to determine the difference in classes and styles on my test forms. The app style was the only difference. Yes, SetWindowLong and GetWindowLong would be the APIs needed to read and set the style.
    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

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Is this form modal?

    To expand a bit on Rob's answer... It's the extended window style that will have the WS_EX_APPWINDOW bit set if the window is not shown modally. You can use this code to check that.
    VB Code:
    1. Private Declare Function GetWindowLong _
    2.  Lib "user32.dll" Alias "GetWindowLongA" ( _
    3.     ByVal hWnd As Long, _
    4.     ByVal nIndex As Long _
    5. ) As Long
    6.  
    7. Public Function IsFormModal(ByVal hWnd As Long) As Boolean
    8.     Const GWL_EXSTYLE As Long = -20
    9.     Const WS_EX_APPWINDOW As Long = &H40000
    10.     IsFormModal = Not ((GetWindowLong(hWnd, GWL_EXSTYLE) And _
    11.                         WS_EX_APPWINDOW) = WS_EX_APPWINDOW)
    12. End Function
    Simply pass the hWnd of the Form you want to check to the IsFormModal function.

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Is this form modal?

    I know that SetWindowLong should be used, but is there any chance you've stumbled accross this anywhere? I had searched quite a bit a while ago and couldn't find anything and although that made sense couldn't find any examples and I couldn't be bothered to test too much myself...


    Has someone helped you? Then you can Rate their helpful post.

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

    Re: Is this form modal?

    If you mean me manavo11 then its just a matter of doing a little testing. Guess I had the time and energy this morning to do it.
    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

  10. #10
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Is this form modal?

    Quote Originally Posted by RobDog888
    If you mean me manavo11 then its just a matter of doing a little testing. Guess I had the time and energy this morning to do it.
    Yep, talking to you I couldn't figure out how I could set that style but also specify the hwnd of the other window that you want to be the parent form/window (external in my case).


    Has someone helped you? Then you can Rate their helpful post.

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Is this form modal?

    Unfortunatly this is not true.... The WS_EX_APPWINDOW means that the window is shown in the TaskBar. It doesn't mean the form is modeless. If you set the BorderStyle of a Form to, for example, Fixed Dialog it will not have this window style regardless if that form is loaded modally or not.

  12. #12
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Is this form modal?

    So much for that idea then...


    Has someone helped you? Then you can Rate their helpful post.

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

    Re: Is this form modal?

    Ah, so it is. Guess I didnt test it throughly enough. My bad.

    So then any insight on what is the identifier JA?
    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

  14. #14
    Hyperactive Member
    Join Date
    Apr 2004
    Posts
    342

    Re: Is this form modal?

    You can check to see if you main form is enabled or not. If there is a form displayed modal then the form that brought it up is disabled.

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

    Re: Is this form modal?

    Quote Originally Posted by tward_biteme1
    You can check to see if you main form is enabled or not. If there is a form displayed modal then the form that brought it up is disabled.
    The form really isn't disabled, you just can't do anything with it, or any other window, until the modal form has been unloaded.

  16. #16
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Is this form modal?

    It's pretty easy to create a Private property in a form so you can tell if it's modal or not.

    CreateForm1 with two command buttons and form2 (the form to be shown vbModal) with one command button

    VB Code:
    1. ' Form1 code
    2. Option Explicit
    3.  
    4. Private Sub Command1_Click()
    5.  
    6.     Form2.ShowForm = vbModal
    7.    
    8. End Sub
    9.  
    10.  
    11. Private Sub Command2_Click()
    12.  
    13.     Form2.ShowForm = vbModeless
    14.    
    15. End Sub
    16.  
    17. ' Form2 code
    18. Option Explicit
    19. Private mintMode As Integer
    20. Private Sub Command1_Click()
    21.  
    22.     If Form2.ShowForm = vbModal Then
    23.         MsgBox "vbModal"
    24.     Else
    25.         MsgBox "Modeless"
    26.     End If
    27.    
    28. End Sub
    29. Public Property Get ShowForm() As Integer
    30.  
    31.     ShowForm = mintMode
    32.  
    33. End Property
    34.  
    35. Public Property Let ShowForm(ByVal intMode As Integer)
    36.  
    37.     If IsMissing(intMode) Then
    38.         mintMode = vbModeless
    39.     Else
    40.         mintMode = intMode
    41.     End If
    42.  
    43.     Me.Show intMode
    44.    
    45. End Property

  17. #17
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Is this form modal?

    We had a need to "know" if a modal form was popped up on the screen - because we were subclassing for the APPACTIVATE message...

    And if we messed with FORM focus with a MODAL form on the screen, VB choked.

    We ended up creating a global boolean to track whenever a MODAL form was put on the screen so we could test that boolean.

    One odd place this was required was when we started printing with the PRINTER object and the user had a PDF-writer as the default printer. That PDF-writer would pop-up a file dialog box to ask for output filename. So we needed to set that global boolean at the start of a report as well.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  18. #18
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Is this form modal?

    Quote Originally Posted by Hack
    The form really isn't disabled, you just can't do anything with it, or any other window, until the modal form has been unloaded.
    Well, actually the owner form is disabled. However the Enabled property in VB isn't set but you can check if the owner form has the WS_DISABLED style bit set.

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