How to bring a dialog toFront?

I’ve got an application that runs from the system tray. Before showing its window, I do some tests, and if those tests fail, I throw up an alert box using DialogWindow::showModalDialog().

This usually works fine, but testers have said that this dialog window sometimes fails to show in front of other windows already on the screen. How can I force this dialog to come to the fore? Since the dialog is created and run by the DialogWindow class, I don’t really have a chance to call toFront().

Perhaps there’s a better way to avoid this situation in general?

Normally it should bring itself to the front, but sometimes Windows can deliberately stop this happening if the task isn’t the foreground task. Not sure what the rules are for this. If you really need to force it, you could always control the window yourself rather than using the showModalDialog call.

I rewrote things to do a toFront() before entering the modal loop, only to find out that showModalDialog() actually calls toFront() indirectly. It didn’t make a difference, however, as the dialog still appears behind the windows of active processes.

This doesn’t happen in the debugger, however. The dialog pops to the front nicely. I’ve never had the main window of the app fail to come to the fore, so there must be different rules about foreground and background tasks. Is there a way to force my app to become the foreground task without it’s system tray icon being clicked on?