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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recognize whether modal form is open

Status
Not open for further replies.

Roderich

Programmer
Sep 11, 2001
58
DE
hi,

I need to recognize whether any modal form is currently opened in my application, either an own form or any message window. I need this because my application should react to a message from another task, but only if it's "idle", that is the user didn't open any modal dialog.

I tried this trick in my GetMessage procedure inside my main form:

..
SetFocus;
if not Self.Active then
exit;
..

I assumed this should work to determine whether any modal window prevents giving focus to the main window. But sometimes it fails for some strange reason (my debugger then says the main form is active).

So is there any other way to determine whether a modal form is currently open ?

regards
Rod
 
Have a form-less unit with a variable

Modal_Open:Integer;

Make each form use that unit and in the OnShow events of each modal window put

inc(Modal_Open);

In the OnClose event put

dec(Modal_Open);

Then if you want to know if any are open, check for Open_Modal = 0
 
thanks Ragnafar for your proposal. I also thought of that way but for 2 reasons I didn't want that:

First I could forget to set the counter in any of my modal forms since my project has more than 60 forms at the moment with even more to be added even out of DLL's.
The second reason is that there also could be a MessageBox open which normally prevents user input.

So I'm still looking for the other way, detecting whether my main form could be activated at all before performing some action.

best regards
Rod
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top