Try a handler for the Screen.OnActiveFormchange event, that may work for your purpose.
I tried this - but it has two problems...
Code:
procedure TMyForm.ScreenActiveFormChange(
sender_ : TObject );
var
frmActive : TCustomForm;
bIsModal : Boolean;
ctrlForeground : TWinControl;
begin
ctrlForeground := FindControl(
Windows.GetForegroundWindow() );
frmActive := nil;
bIsModal := false;
if ( Assigned(ctrlForeground) and
(ctrlForeground is TCustomForm) ) then begin
frmActive := TCustomForm( ctrlForeground );
bIsModal := ( fsModal in frmActive.FormState );
end;
...
1.) how do I get if the foreground window is modal?
I find the correct foreground Form in the above code snippet but the FormState never contains fsModal - only fsVisible...
2.) the procedure will not be called if a dialog pops up (e.g. a TPrinterSetupDialog)
EDIT: I even tried to use Screen.OnActiveControlChange - with same result (will also not be called if the modal foreground dialog e.g. is a TPrinterSetupDialog).