CybrHwk
CybrHwk

Reputation: 95

Making a corner of the desktop activate screensaver

I am trying to write a simple application to activate my screensaver when the mouse in at the top right corner of the screen. I have found an answer to controlling the screensaver from C# however I am having trouble working out how to do a "hot corner" type check for the mouse position. This is the only part I am stuck with, any help would be appreciated.

This Activates the screensaver

[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
    private static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int  lParam);

private const int SC_SCREENSAVE = 0xF140;
private const int WM_SYSCOMMAND = 0x0112;

public static void SetScreenSaverRunning()
{
  SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0);
}

Upvotes: 4

Views: 741

Answers (3)

weasel5i2
weasel5i2

Reputation: 119

You could also try ScrHots from Lucian Wischik. It's freeware and does exactly what you need, and also has hot-corners for "never activate the screensaver" capability. All four corners can be programmed to do either function. I've used this one for years, and it works great.

http://www.wischik.com/scr/savers.html (ScrHots3, under the "Utilities" section)

Hope this helps someone.

Upvotes: 0

makman99
makman99

Reputation: 1094

I have made the exact same thing, only it loads in the top left. What I did was just make the form size 1px by 1px with no border, and just activate the screensaver when the mouse stays over the form for a second. Doing it this way requires that you find all ways to keep the form on top of everything.

Another option would be mouse hooking and just watching for (0,0) mouse position, or for the top right - (0, screen.width)

Upvotes: 1

Jason Down
Jason Down

Reputation: 22171

You could use the System.Windows.Form.Screen class to get the current resolution (take a look at this answer). Then use Cursor.Position.Property to determine where the cursor is currently located (i.e. is it within the boundaries of some predefined rectangle that should activate it).

Upvotes: 4

Related Questions