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?
Printable View
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?
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.
Do you know how to interrogate a form's window style? Presumably by some API call?
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)? :D I'm probably asking for too much :D
I think it's the GetWindowLong you need.Quote:
Originally Posted by simonm
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.
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.Simply pass the hWnd of the Form you want to check to the IsFormModal function.VB Code:
Private Declare Function GetWindowLong _ Lib "user32.dll" Alias "GetWindowLongA" ( _ ByVal hWnd As Long, _ ByVal nIndex As Long _ ) As Long Public Function IsFormModal(ByVal hWnd As Long) As Boolean Const GWL_EXSTYLE As Long = -20 Const WS_EX_APPWINDOW As Long = &H40000 IsFormModal = Not ((GetWindowLong(hWnd, GWL_EXSTYLE) And _ WS_EX_APPWINDOW) = WS_EX_APPWINDOW) End Function
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... :D
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. :D
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).Quote:
Originally Posted by RobDog888
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.
So much for that idea then... :(
Ah, so it is. Guess I didnt test it throughly enough. My bad. :(
So then any insight on what is the identifier JA?
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.Quote:
Originally Posted by tward_biteme1
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:
' Form1 code Option Explicit Private Sub Command1_Click() Form2.ShowForm = vbModal End Sub Private Sub Command2_Click() Form2.ShowForm = vbModeless End Sub ' Form2 code Option Explicit Private mintMode As Integer Private Sub Command1_Click() If Form2.ShowForm = vbModal Then MsgBox "vbModal" Else MsgBox "Modeless" End If End Sub Public Property Get ShowForm() As Integer ShowForm = mintMode End Property Public Property Let ShowForm(ByVal intMode As Integer) If IsMissing(intMode) Then mintMode = vbModeless Else mintMode = intMode End If Me.Show intMode End Property
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.
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.Quote:
Originally Posted by Hack