views:

147

answers:

2
var ScreenSaver:String;
var handle:HWND;
begin
Handle := FindWindow('Progman', 'Program Manager');
Handle := FindWindowEx(Handle, 0, 'SHELLDLL_DefView', 0);
Handle := FindWindowEx(Handle, 0,'SysListView32', 'FolderView');

ScreenSaver := 'C:\windows\system32\Mystify.scr /P' + InttoStr( Handle );
WinExec(pAnsichar(screensaver), SW_SHOWNormal);

This code will erase the desktop icons.
How to get the window handle behind the desktop icons?

+2  A: 

This isn't really a Delphi question, but anyway... Starting a screen saver with the /P command line switch creates the screen saver window as a child of the given window, with the same size and position - it is meant only to provide a screen saver preview in the Display Properties dialog box. It will not position the screen saver window somewhere in the Z-order beneath some other window. Consequently it will draw over everything, erasing the desktop icons as well.

Unless you create your own screen saver that draws directly on the desktop window I don't think what you want can be done.

mghie
A: 

As mghie indicates, if you're wanting to start a screensaver, that's not the correct way to do it. Easiest way is:

SendMessage(Handle, WM_SYSCOMMAND, SC_SCREENSAVE, 0);

In my experience, I again agree with mghie; I don't think you can do what you're wanting to do. Windows seems to operate in a different environment when a screensaver is active, e.g. Windows messages don't seem to propagate as expected, etc.

Although, to get at the desktop, I've previously used a handle to the Device Context of the desktop.

var
  ScreenDC: HDC;
begin
  ScreenDC := GetWindowDC(0);
  ...
  // You can then use the Device Context with Windows API methods such as BitBlt
  // and StretchBlt to go graphical work on the desktop.}
  ...
  ReleaseDC(0, ScreenDC);
Conor Boyd