Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to check if Application is waiting for user modal answer

3 views
Skip to first unread message

rfor...@gmail.com

unread,
Sep 11, 2008, 2:56:52 PM9/11/08
to
Hi,

I have an app with a main TForm A sometimes calling a modal TForm B or
a simple MessageBox. On the same TForm A I have a timer. I would
like this timer to check if the app is waiting for a modalResult of
either TForm B / MessageBox.

Something like :

procedure TForm1.Timer1Timer(Sender: TObject);
begin
// Of course, modalWindowActive doesn't exists, but you get the
idea...
if TApplication.modalWindowActive then Edit1.Text := 'App is busy
waiting for user...'
else Edit1.Text := 'App is not
busy...';
end;

Anyone?

Jamie

unread,
Sep 11, 2008, 10:06:30 PM9/11/08
to
You can use the API call."GetActiveWindow" which will return the
currently HANDLE of the focused window in your thread.

With the API returned handle , you can then use that to query
information about the window to ID it. Like the GetWindowText
for example...

Of course, if you have these windows pre initiated in the
background, you could always check the ACTIVE property.


http://webpages.charter.net/jamie_5"

Rob Kennedy

unread,
Sep 12, 2008, 12:45:13 AM9/12/08
to
rfor...@gmail.com wrote:
> I have an app with a main TForm A sometimes calling a modal TForm B or
> a simple MessageBox. On the same TForm A I have a timer. I would
> like this timer to check if the app is waiting for a modalResult of
> either TForm B / MessageBox.

You're in control of both the forms, right? Especially form A, right?

So, before you show the modal form, make a note that you're showing it.
You could do that by setting a Boolean variable, for instance. When the
modal window closes, note that, too.

Now, when you have code that wants to know whether some other code has
done something, it can check.

--
Rob

rfor...@gmail.com

unread,
Sep 16, 2008, 1:06:15 PM9/16/08
to
Thank you all for your comments. I finally found Screen.ActiveForm
and it works pretty well. Here is what I did :

if Screen.ActiveForm <> Application.MainForm then
// There is an opened Window which is not the MainForm

0 new messages