Recent

Author Topic: How to detect if a messagedlg is showing?  (Read 465 times)

Bart

  • Hero Member
  • *****
  • Posts: 3897
    • Bart en Mariska's Webstek
How to detect if a messagedlg is showing?
« 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

440bx

  • Hero Member
  • *****
  • Posts: 1988
Re: How to detect if a messagedlg is showing?
« Reply #1 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.

FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

korba812

  • Full Member
  • ***
  • Posts: 134
Re: How to detect if a messagedlg is showing?
« Reply #2 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

winni

  • Hero Member
  • *****
  • Posts: 1754
Re: How to detect if a messagedlg is showing?
« Reply #3 on: July 09, 2020, 01:45:16 pm »
Hi!

Yes - use TScreen.

There is

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

Winni

ASerge

  • Hero Member
  • *****
  • Posts: 1665
Re: How to detect if a messagedlg is showing?
« Reply #4 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.

Bart

  • Hero Member
  • *****
  • Posts: 3897
    • Bart en Mariska's Webstek
Re: How to detect if a messagedlg is showing?
« Reply #5 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

Bart

  • Hero Member
  • *****
  • Posts: 3897
    • Bart en Mariska's Webstek
Re: How to detect if a messagedlg is showing?
« Reply #6 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

Bart

  • Hero Member
  • *****
  • Posts: 3897
    • Bart en Mariska's Webstek
Re: How to detect if a messagedlg is showing?
« Reply #7 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

ASerge

  • Hero Member
  • *****
  • Posts: 1665
Re: How to detect if a messagedlg is showing?
« Reply #8 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.

Bart

  • Hero Member
  • *****
  • Posts: 3897
    • Bart en Mariska's Webstek
Re: How to detect if a messagedlg is showing?
« Reply #9 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