FMX Message window appears in background

Message dialogs are occasionally appearing in the background behind the application window, instead of in a modal top most window

Alt tabbing a few times sometimes (not sure if always) bring the message window to the front

I suspect this issue is related to a long running routine calling Application.ProcessMessages to refresh the screen and to allow the user to cancel the operation. I expect that converting the code to a thread might resolve the issue, but I want to avoid that if possible as it will require a lot of re-testing

Is there any workaround for this to force the message window to always appear at the top ?

I am displaying the message using vcl.dialogs.MessageDlg

Environment - Delphi 10.1, Windows 10

The only two causes I know of are

  1. Keydown event is used to action things, allowing the previous window to receive keyup, thus changing focus.
  2. The user doubleclicks, again, causing focus to change.

My solution has been to move the dialog window to the front in the idle loop. It still isnt foolproof.

Thanks Rohit

I forgot to mention that this was a FireMonkey application, not VCL.

I havent found a workaround so far, so Ive decided to implement message dialogs using my own custom form. It is fairly easy to do and gives me control over this issue. I already use a messaging unit for all messages, so I just have to redirect that to use the new form instead of the standard FMX dialogs.

So, my issue is now resolved by using my custom form, however I am still interested in other workarounds so please post if you know of anything

You are most likely going to find the answer here, even though it applies to VCL the same problem would be in FMX. MessageBox is hidden by a modal form - VCL - Delphi-PRAXiS [en]

Hi Scott,

We have had this problem a lot over the years. The problem with this call is that you don’t get to pass the parent window through – which I would suggest you should almost always do.

The equivalent windows API has the option of passing a window handle for the parent window, or passing NULL to make the message dialog application modal. From our experience application modal dialogs can have the problem (I have seen the behaviour you describe in versions of outlook for example). The application modal behaviour seems to be a bit flaky in widows, particularly if you have a modeless windows along side your main window, but for some reason Delphi seemed to really exacerbate the problem.

We ended up writing our own wrapper to a call to CreateMessageDialog, setting the dialog popup parent and calling ShowModal. And we always pass the parent window through. This has made a massive improvement to the number of occasions we get the ‘window behind’ issue you seem to be describing.

Cheers,
Duncan.

~WRD0622.jpg

jim2logo-120px_31226bb4-3825-4f42-8787-33b49d016248.png

linkedin-30_d3c8150d-2743-4bac-81b1-5cfde19d4361.png

facebook-30_79013a37-7be4-4029-8a33-5407e4a1f81f.png

youtube-logo-30_d5bc238f-db7d-435a-a6c9-7b4bda94001e.png

twitter-30_96f66de6-db0e-46e2-939c-226219685370.png

jim2usersupport_a104be27-e86f-4df9-8aee-fbcbed02fc4b.png

Thanks @Duncan . Ill try that out

In the meantime I am using a clunky workaround where I created my own custom form to display messages. That is good enough for the application in questions, but I want to look into this further for other applications so Ill look into your suggestions