Sunday, August 22, 2010

Start Screensaver

Today I want to show you, how to start the current screensaver of the computer using C#.
Therefor we need a WinAPI function, as always to be able to include this we first need:

using System.Runtime.InteropServices;

The function needed to load the screensaver is SendMessage(), it is included as follows:

public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);

In general this function allows us to send a message to a specific window. The target window is defined by the parameter hWnd.
The 2nd parameter Msg describes the message, which is supposed to be send.
The last 2 parameters allow us to set additional parameters next the message.
To enable the current screensaver, the following parameters are needed:

SendMessage(this.Handle, 0x112, 0xF140, 0);

No comments:

Post a Comment