views:

213

answers:

3

In order to take a screenshot of a specific window, I need to place a white colored TForm behind that window. What Windows API could I use to change the z-order of my window and place it correctly ?

+3  A: 

Try the SetWindowPos() function.

mghie
+1 - this is the windows way.
skamradt
Exactly what I was looking for. And for the record, it's not that easy to use as you have to make sure that 1- the form's owner is the desktop so it can freely change z-order and 2- You call that function using the SWP_NOACTIVATE flag. Thank you for the fast response.
John Riche
+1  A: 

On Delphi you can useSendToBack method, .Top and .Left properties.

form1.Top := ...;
form1.Left := ...;
form1.SendToBack;

procedure SendToBack;

Description

Use SendToBack to change the order of overlapping controls or forms.

The order in which controls stack on top of each other (also called the Z order) depends on the order the controls are placed on the form. For example, if you put a label and an image on a form so that one is on top of the other, the one that was placed first on the form becomes the one on the bottom. Because both the label and the image are non-windowed controls, they "stack" as you would expect them to. Call the SendToBack method for the top object to move it below the other object.

The stacking order of two windowed controls is the same as the stacking of two non-windowed controls. For example, if you put a memo on a form, then put a check box on top of it, the check box remains on top. Calling SendToBack for the check box makes the memo appear on top.

The stacking order of windowed and non-windowed controls cannot be mingled. For example, if you put a memo, a windowed control, on a form, and then put a label, a non-windowed control, on top of it, the label disappears behind the memo. Windowed controls always stack on top of non-windowed controls. In this example, calling the SendToBack method of the memo does nothing, the label remains behind the memo.

If the control has the input focus when the SendToBack method executes, it loses the input focus.

(Edit: WinSnap is a very good utility for taking and editing screenshots)

Nick D
He wants the white form *immediately* behind the target window, not behind *all* other windows. I suspect he wants the white background so that Windows XP's curved corners and Windows Vista's glass borders aren't sullied by other arbitrary patterns behind them.
Rob Kennedy
Exactly Rob. The solution was to use the SetWindowsPos() API as suggested by mghie.
John Riche
A: 

If you can get the handle of the window you want in front then I would assume that: Pseudo Code:

MyAppWindow.BringToFront

followed by

TargetWindow.BringToFront

Should have the desired effect, yes?

Despatcher