Lazarus

Programming => LCL => Topic started by: Bart on July 09, 2020, 01:11:45 pm

Title: How to detect if a messagedlg is showing?
Post by: Bart on July 09, 2020, 01:11:45 pm
Hi,

When my app fires an event, I need to know if at that time I have a MessageDlg (or some other system dialog) open.

How to figure that out?

Bart
Title: Re: How to detect if a messagedlg is showing?
Post by: 440bx on July 09, 2020, 01:34:29 pm
When my app fires an event, I need to know if at that time I have a MessageDlg (or some other system dialog) open.

How to figure that out?
Presuming your question is on Windows and that the MessageDlg is owned by your application (not the desktop for instance), one fairly simple way is to enumerate the windows owned by your app.  There is usually a piece of information you can obtain using the window handle that will allow you to identify a dialog. 

HTH.

Title: Re: How to detect if a messagedlg is showing?
Post by: korba812 on July 09, 2020, 01:41:00 pm
Maybe TScreen.Forms property will be useful in this case.
https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tscreen.forms.html (https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tscreen.forms.html)
Title: Re: How to detect if a messagedlg is showing?
Post by: winni on July 09, 2020, 01:45:16 pm
Hi!

Yes - use TScreen.

There is

Code: Pascal  [Select][+][-]
  1. function GetCurrentModalForm: TCustomForm;

Winni
Title: Re: How to detect if a messagedlg is showing?
Post by: ASerge on July 09, 2020, 03:42:32 pm
When my app fires an event, I need to know if at that time I have a MessageDlg (or some other system dialog) open.
Application dialogs - by (Application.ModalLevel > 0). System dialogs - using System API.
Title: Re: How to detect if a messagedlg is showing?
Post by: Bart on July 09, 2020, 06:49:13 pm
There is

Code: Pascal  [Select][+][-]
  1. function GetCurrentModalForm: TCustomForm;

That simply returns nil, wether or not I have a MessageDlg() showing.

Bart
Title: Re: How to detect if a messagedlg is showing?
Post by: Bart on July 09, 2020, 06:52:37 pm
Presuming your question is on Windows ...

I'ld prefer a cross platform solution, I use that app on both Windows and Linux.

... and that the MessageDlg is owned by your application (not the desktop for instance)

The MesssageDlg is just that: a call to the function MessageDlg(), GOK if the resulting form/dialog is owned by me or by some other "thing" in my system.

Bart
Title: Re: How to detect if a messagedlg is showing?
Post by: Bart on July 09, 2020, 06:53:52 pm
Application dialogs - by (Application.ModalLevel > 0). System dialogs - using System API.

My fault: I mean the dialog shown by MessageDlg() or ShowMessage() functions.

Bart
Title: Re: How to detect if a messagedlg is showing?
Post by: ASerge on July 09, 2020, 06:57:39 pm
Application dialogs - by (Application.ModalLevel > 0). System dialogs - using System API.

My fault: I mean the dialog shown by MessageDlg() or ShowMessage() functions.
So Application.ModalLevel > 0.
Title: Re: How to detect if a messagedlg is showing?
Post by: Bart on July 09, 2020, 07:13:39 pm
Application dialogs - by (Application.ModalLevel > 0). System dialogs - using System API.

My fault: I mean the dialog shown by MessageDlg() or ShowMessage() functions.
So Application.ModalLevel > 0.

Yep, that seems to work!

Bart
TinyPortal © 2005-2018