Issues with putting a form behind everything else on the desktop
Posted on 2004-10-13
I'm hoping someone can clarify an issue for me, and suggest a solution.
I need to display a form containing data collected, when it arrives, but I
want the form to appear behind whatever other windows are showing on the user's
desktop, so as not to disturb whatever they may be doing at the moment.
(By the way, the application's main window is not displayed, either, but
rather "minimized to the icon tray")
As long as I let Delphi auto-create the form for me, the following worked
if PopUnder then
frmNewMail.Visible := true;
The form does not receive focus AND it appears behind everything else on the
desktop. The form was removed from view using a standard Close, when the
user clicked a button.
Now, I wish to create this form at run-time, and it has been removed
from Delphi's auto-create list. Instead I use:
if not VNewMailWinExists then
VNewMailWinExists := true;
vNewMailWin := TfrmVNewMail.Create;
if PopUnder then
vNewMailWin.Visible := true;
And the form is set to caFree when asked to Close.
With this scheme, the Form behaves as expected the first time it is
displayed, but on subsequent runs of the above code lines, the form appears
in front of everything else (but unfocused, as expected).
(The forms Create method has been overridden, and the Owner is set to Nil,
rather than Application. Setting Owner to Application (as a test) did not
seem to have any effect, though)
So, the question is, can someone please explain why this is happening, i.e.
why does it appear behind on the first run, and on top after that?
And why is a run time created form behaving differently from a Delphi
A suggestion for a good way to do this will be appreciated.
SetWindowPos(vNewMailWin.Handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE
or SWP_NOSIZE or SWP_NOACTIVATE);
works, but seems to have the undesireable effect that the user must click
the top, form bar to bring the form into view, instead of just clicking
anywhere on the form.