mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Gamma Init
This commit is contained in:
56
app/WindowsDisplayAPI/Native/DeviceContext/DCHandle.cs
Normal file
56
app/WindowsDisplayAPI/Native/DeviceContext/DCHandle.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.DeviceContext
|
||||
{
|
||||
internal class DCHandle : SafeHandle
|
||||
{
|
||||
private readonly bool _created;
|
||||
|
||||
private DCHandle(IntPtr handle, bool created) : base(handle, true)
|
||||
{
|
||||
_created = created;
|
||||
}
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get => handle == IntPtr.Zero;
|
||||
}
|
||||
|
||||
public static DCHandle CreateFromDevice(string screenName, string devicePath)
|
||||
{
|
||||
return new DCHandle(
|
||||
DeviceContextApi.CreateDC(screenName, devicePath, null, IntPtr.Zero),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public static DCHandle CreateFromScreen(string screenName)
|
||||
{
|
||||
return CreateFromDevice(screenName, screenName);
|
||||
}
|
||||
|
||||
public static DCHandle CreateFromWindow(IntPtr windowHandle)
|
||||
{
|
||||
return new DCHandle(
|
||||
DeviceContextApi.GetDC(windowHandle),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public static DCHandle CreateGlobal()
|
||||
{
|
||||
return new DCHandle(
|
||||
DeviceContextApi.CreateDC("DISPLAY", null, null, IntPtr.Zero),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
return _created
|
||||
? DeviceContextApi.DeleteDC(this.handle)
|
||||
: DeviceContextApi.ReleaseDC(IntPtr.Zero, this.handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user