Detect showing of modal window

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any way to detect when a modal window has been shown by your
application without any knowledge of the window that was shown? For example,
when the main form of you app is disabled, is there any way to determine that
the form was disabled due to a modal window being displayed (as opposed to a
modeless window being displayed)? Of course there might be a much more
elegant solution.

Thanks,
Lance
 
Hi Lance,

I don't know of a .Net way and I've never come across an API although I'm
sure it is there. An elegant way may be to create a base form control and
have all your forms inherit from this. Then create a shared class which has
an event that fires which is captured by your base form. In the Load of
your base form check if it is modal, if so raise the event on your shared
class passing it the handle of the form. Now every form you have running in
your app should capture this event and respond. In your base form class set
the title of your form to CurrentTitle + " - Blocked By Modal" if the handle
passed to the event doesn't match the form. That is off the top of my head
but it just might do it. Hmmm.... Calling a modal form is a blocking event
I believe so that may not work. How about having the base form launch a
thread for each time it is created, that thread simply monitors the Shared
classes variable. If the variable isn't 0 and it doesn't match the form's
handle then change the title of the form. That's it! That'll work for
sure. Don't forget to put code in your base class in the closing event that
checks if it is modal and if so sets that Shared variable back to 0. You'll
probably need to use a flag then also that is monitored in that spun off
thread of each form so they know when to reset their titles. Good luck!
Ken.
 
Thanks a lot for the idea. A problem though is that many of the modal
windows are not accessable (e.g., MessageBox or OpenFileDialog from a
FileNameEditor). I might have another idea though so I'll test it out and
report back.

Lance
 
Hi

I think we have no good method to know if currently the modal dialog is
opened, because when modal dialog is opened, the whole the thread will be
block, only the modal dialog return.
So we have to check the status before we open the modal dialog.
e.g. we can set a flag before we call the MessageBox or OpenFileDialog as
Ken said.


Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Lance,

I have two ideas. One is in that base class to create your own functions
that simply wrap the calls to MessageBox and etc., then you can implement
what we talked about before. My other idea is totally untried but it might
be worth it. There is a GetWindow() API that will return all the style bits
for a window. When a Window is disabled &8000000 is set. I'm not sure if
this applies to windows blocked by a modal window or just controls like
textboxes and stuff but it might be worth a shot. Then all you need to do
in that base class is launch a separate thread and monitor this style bit.
Could be worth a shot. Good luck! Ken.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top