Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I discover if my delphi application currently has a modal window?

I've got a timer running in my Delphi MDI application and I'd like to use it to pop up a message if something changes in the background. But I don't want that message to pop up when the the application has a modal dialog in the foreground because the user couldn't do anything about it.

So what I'd like to know is how can I check for the existence of a modal dialog in my application?

like image 209
Peter Turner Avatar asked Nov 12 '08 16:11

Peter Turner


People also ask

What is a modal window software?

In user interface design for computer applications, a modal window is a graphical control element subordinate to an application's main window. A modal window creates a mode that disables the main window but keeps it visible, with the modal window as a child window in front of it.

Why is it called a modal dialog?

With a modal dialog, you set your application in a particular mode (a different "state" if you will), whereby only actions pertaining to that "mode" are accepted, hence preventing UI actions outside of the dialog. Restrictive or limited interaction due to operating in a mode.

What is the use of modal dialog?

Definition: A modal dialog is a dialog that appears on top of the main content and moves the system into a special mode requiring user interaction. This dialog disables the main content until the user explicitly interacts with the modal dialog.


5 Answers

You could try with this code:

var
  ActForm: TCustomForm;
begin
  ActForm := Screen.ActiveForm;
  if (ActForm = nil) or not (fsModal in ActForm.FormState) then begin

  end;
end;

I tested with Delphi 4, works for me.

[EDIT]: But you should really think about whether popping up a form and stealing focus is a good idea. It depends on your application, but if a user is currently entering something into an edit field, or doing something with the mouse, then this might break their workflow.

like image 120
mghie Avatar answered Oct 12 '22 22:10

mghie


Since Delphi 2005 you have a ModalLevel property on TApplication. It counts the number of Modal forms opened in the application.

like image 43
Lars Truijens Avatar answered Oct 12 '22 22:10

Lars Truijens


Perhaps the solution is to actually pop up a hint which doesn't steal focus. A clickable hint somewhere visible, but not too invasive. Thus, if the user wants to take action they can, or they can finish off what they were doing, then take action. Or perhaps ignore it altogether.

like image 35
Steve Avatar answered Oct 13 '22 00:10

Steve


use AnyPopup() function

About GetLastActivePopup(). It may return value is the same as the hWnd parameter when

  • The window identified by hWnd was most recently active.
  • The window identified by hWnd does not own any pop-up windows.
  • The window identifies by hWnd is not a top-level window, or it is owned by another window.
like image 45
histrio Avatar answered Oct 12 '22 23:10

histrio


Today user histrio correctly answered in another thread that just monitoring modal Delphi forms is not enough; Windows can also have modal dialogs.

His answer in another thread shows you how to check for that.

--jeroen

like image 33
Jeroen Wiert Pluimers Avatar answered Oct 13 '22 00:10

Jeroen Wiert Pluimers