views:

327

answers:

2

I'm using Delphi 4. I have a main form with a button that dynamically creates a new form. I'd like the new form to be visible, but to show up BEHIND the main form.

I've tried calling SendToBack() immediately after FormCreate(). But that makes the window flicker quickly before it's actually sent to back.

I've tried making the form invisible, then SendToBack(), then Visible := true. But the new form is still at the front.

It looks like SendToBack() only works with visible forms? How can I cause the form to be shown behind the main form?

A: 

make the second window (e.g. form2) invisible, then call:

showWindow(form2.handle,SW_SHOWNOACTIVATE);

-don

Don Dickinson
Thanks but that didn't work.if I call ShowWindow(newform.handle, SW_SHOWNOACTIVATE), then newform.Visible := true. It still comes out in front.
Clement
why call newform.visible :=true; ? if you leave that out, it should work.
Don Dickinson
Later on, i check "if(newform.visible) then do-stuff;". But using the showWindow() without the visible:=true, the visible property seems to be false.
Clement
+1  A: 

This worked for me:

SetWindowPos(newform.Handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_SHOWWINDOW
  or SWP_NOMOVE or SWP_NOOWNERZORDER or SWP_NOSIZE or SWP_NOACTIVATE);

newform.Visible := true;

Thanks for help!

Clement