Files
mirror-processhacker/trunk/ProcessHacker.Native/Objects/DesktopHandle.cs
T
flavioe 2106d2a2e6 changed API definitions to use IntPtr instead of int
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@1233 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2009-05-05 22:05:59 +00:00

50 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using ProcessHacker.Native.Api;
using ProcessHacker.Native.Security;
namespace ProcessHacker.Native.Objects
{
public class DesktopHandle : Win32Handle<DesktopAccess>
{
public static DesktopHandle GetCurrent()
{
return GetThreadDesktop(Win32.GetCurrentThreadId());
}
public static DesktopHandle GetThreadDesktop(int threadId)
{
IntPtr handle = Win32.GetThreadDesktop(threadId);
if (handle == IntPtr.Zero)
Win32.ThrowLastError();
return new DesktopHandle(handle, false);
}
public DesktopHandle(string name, bool allowOtherAccountHook, DesktopAccess access)
{
this.Handle = Win32.OpenDesktop(name, allowOtherAccountHook ? 1 : 0, false, access);
if (this.Handle == System.IntPtr.Zero)
Win32.ThrowLastError();
}
private DesktopHandle(IntPtr handle, bool owned)
: base(handle, owned)
{ }
protected override void Close()
{
Win32.CloseDesktop(this);
}
public void SetCurrent()
{
if (!Win32.SetThreadDesktop(this))
Win32.ThrowLastError();
}
}
}