Link to home
Start Free TrialLog in
Avatar of PAG_Promax

asked on

Modal Dialog Showing Behind Other Forms/Parent App

Hi there,

We have an older (still in development) product in the market which has a problem running under Citrix.  The application is essentially an MDI application, but in one particular place, two modal dialog boxes are created over the MDI child form.

So,  MDI application -> MDI Child -> Modal Dialog -> Modal Dialog Selection Screen

At the point where the Modal Dialog Selection Screen is shown, quite often the form is actually drawn behind either the owner form, or even the MDI Child (we think it may even be drawn behind the MDI application itself).

On each of the forms, I've added to the FormActivate event BringToFront.  I've also removed all processing work from the OnCreate and OnShow events so that the form is definately drawn before anythng happens.

Can anyone tell me how I can fix this?  We're banging our heads against the way because the client can consistently reproduce it.  It is possible to reproduce this running the app under Windows, but it's a lot harder to do so.

If you need any more information, please ask.  We're desperate for an answer.

Many Thanks,


PS.  I'm posting this in multiple forums because I'm hoping someone may have an idea who isn't just in the Delphi forum.
Avatar of jkr
Flag of Germany image

Can you reproduce that on a non-Citrix client at all? I remember a couple of occasions in the past where a Citrix update/serice pack/fix got rid of such issues...
Avatar of PAG_Promax



Apparently my co-worker can repro it under Windows, but I haven't been able to. The worst I've seen in the modal window appearing slightly behind another modal window.  But it was a simple matter of moving it out the way and then everything is fine again.

What we have just found out is one of the dialog boxes is actually being drawn out of the client display area!  Its left hand edge > width of the screen.  I'm not sure why this is the case.  I'm just changing some code to centre all the forms in the hope that it fixes the problem.

Will keep you posted.


>>>> We have an older (still in development) product

How old? What version of VC it is built with?

When the modal dialog was activated, the parent frame window (MDI Frame) was disabled, hence the message loop in CWinApp::Run is no longer active as well, cause the modal dialog runs its own message pump. Depending on the VC version the behavior can be slightly different. If you have a debug version running you could try to set a breakpoint to the application's message loop while the dialog is opened. If the message loop is still running (and didn't wait for enabling somewhere) you could add a timer handler, which periodically sets the focus to the modal dialog what should bring it into top most position. If the message loop wasn't running you could invoke a Windows timer where the callback function also would try to refocus the modal dialog.

Regards, Alex

>>>> I'm just changing some code to centre all the forms in the hope that it fixes the problem.
The hiding of modal dialog boxes was a common issue for older Windows version (I think I experienced it at W2K recently as well). It often happened if the user clicked more than once to a button which invoked the modal dialog. Then, the second click activated the window which was behind the form with the button and the modal dialog which comes later was hidden. The Citrix server often was based on former Windows versions and/or have a different timing what might be a reason for the failing.
When I have run into problems with the ZOrder being incorrect I have been able to use this function to force it to straighten out.


Let me know if it helps.
P.S.  You would likely have to use SetForegroundWindow in the OnActivate of your modal dialog.  That being the case the correct code would be:

HI Folks,

Thanks very much for you help so far with this.  I'll try developentguru's suggestion now and see if it solves the problem.

itsmeandnobodyelse: This is written in Delphi, but I'm hoping that someone in the C++ community may have experienced it as well.  I can apply suggestions from C++ into Delphi without a problem.

Thanks folks.  Much appreciated.  Any more ideas would be fantastic!

Just an update....

We've tried pretty much everything we can find, and we've sent an update to the client to see if it is fixed or not, but we've heard nothing back yet.  We've also sent them more info from the Citrix Knowledge Base which documents this fault, but a fix for it.  Again, we've heard nothing.

I'll keep you all informed.

Many thanks,

Avatar of PAG_Promax

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial