Cant focus Firemonkey application when modal dialog open, unless modal dialog itself is clicked


I have an application in which users, upon logging in, are prompted with a modal dialog where they must choose the facility they wish to work out of. At this stage, the application looks like this:

The modal dialog is shown by calling this method:

bool __fastcall ShowFacChoiceForm()
TFacChoiceForm *Form = new TFacChoiceForm( Application );

bool Result = ( Form->ShowModal() == mrOk );

delete Form;

return Result;

In this case, TFacChoiceForm inherits from TForm so the ShowFacChoiceForm() function is calling the standard TForm.ShowModal method documented here.

The issue I am running into is that if my application loses focus, it cannot become the active window again unless the modal dialog itself is clicked. To better illustrate this, I will present the following scenario:

Lets say its Friday afternoon and I decide to goof off a bit and read some web comics. With my application open, I open up another window on top of it, like so:

Then, out of nowhere my boss comes in for a performance review, and I attempt to refocus my application by clicking somewhere on the main form. For example, at the position of this red X in the next image.

In the above image, I have clicked at the location of the red X. Now, both the form containing the web comic, and my application are inactive. Thus, my application does not come to the front of the screen.

However, if I am able to click somewhere on the modal dialog, like the red X in the following image…

…then my application comes to the front like one would expect.

To solve this, I have looked at using something like SetForegroundWindow from the Windows API, but I have not been able to find a way to trigger the event, since my main form does not fire events while I have a modal dialog open.

My question is, how can I make sure that if the user clicks anywhere on my application that it is brought to the front? Is there a property I can edit in my form to do this?

Comments are closed.