Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining modal at runtime? 2

Status
Not open for further replies.

Sashanan

Programmer
Jan 19, 2001
235
NL
Is there any way I can determine at runtime if the form that is currently active has been opened modal or non-modal? I couldn't find a form property for this. I could, I suppose, use a boolean variable blnModal which is updated by the routines in which I open the form (false for non-modal, true for modal), but is there a more elegant solution?


"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
Did you make any progress with this?

I am interested in detecting the same thing.

Thanks
 
Seeing you open the form via your code why not just hold that information some place you can retrieve it?


Hope I've been helpful,
Wayne Francis

If you want to get the best response to a question, please check out FAQ222-2244 first
 
That's indeed what I did, just used a global boolean which is set to true when I'm opening forms modal and false when I'm opening them regularly. Couldn't find any other way to do it; probably because the idea of opening the same form in both ways in one application is uncommon to begin with.


"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
You could use API's to determine whether your application is in a modal state, either by having a modal form open or by having a message box active.
When the application is made modal all forms have the disabled style set so you could check any open form in your application.

Code:
Private Const GWL_STYLE   As Long = (-16)
Private Const WS_DISABLED As Long = &H8000000
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Public Function AmIModal() As Boolean
Dim ll_Style As Long
Dim lb_AmIModal As Boolean

    ll_Style = GetWindowLong(frmToCheck.hWnd, GWL_STYLE)
    If ((ll_Style) And (WS_DISABLED)) Then
       AmIModal = True
    Else
       AmIModal = False
    End If
End Function

Gavin
 
Hey, that works nicely. Do need to pass it a form (to use in place of frmToCheck), but that was easily added. Thanks!


"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
Although I find that if you use this function on the current from while you're in a command button's click event, the wrong result comes out. I assume there's some problem with the form losing the focus when you did that. Solved this by setting frmtocheck to always check the startup form of my application, which never closes and is never the form from which this function is called.


"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
I am glad it has worked for you.
In my application I just check my main MDI form because as I said in the original post, if your form is in a modal state the style is set on all the forms within your application.

-- Gavin
 
Have another star Gavin. Although I have adopted a more simplistic approach, yours set me down the right track.

I have an MDI form (FrmMenu) sitting behind all my windows so I simply need to interrogate its Enabled property to establish whether the current form is modal or not.
 
You guys can also use:


fsModal in MyForm.FormState



this will evaluate to true if the form is modal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top