-
Notifications
You must be signed in to change notification settings - Fork 3
/
WindowHandle.cs
65 lines (57 loc) · 2.05 KB
/
WindowHandle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//-----------------------------------------------------------------------
// <copyright>
// Created by Matt Weber <matt@badecho.com>
// Copyright @ 2024 Bad Echo LLC. All rights reserved.
//
// Bad Echo Technologies are licensed under the
// GNU Affero General Public License v3.0.
//
// See accompanying file LICENSE.md or a copy at:
// https://www.gnu.org/licenses/agpl-3.0.html
// </copyright>
//-----------------------------------------------------------------------
using System.Runtime.InteropServices;
namespace BadEcho.Interop;
/// <summary>
/// Provides a level-0 type for window handles.
/// </summary>
/// <suppressions>
/// ReSharper disable UnusedMember.Local
/// </suppressions>
public sealed class WindowHandle : SafeHandle
{
/// <summary>
/// Initializes a new instance of the <see cref="WindowHandle"/> class.
/// </summary>
/// <param name="handle">The handle to the window.</param>
/// <param name="ownsHandle">Value indicating if this safe handle is responsible for releasing the provided handle.</param>
public WindowHandle(IntPtr handle, bool ownsHandle)
: this(ownsHandle)
{
SetHandle(handle);
}
/// <summary>
/// Initializes a new instance of the <see cref="WindowHandle"/> class.
/// </summary>
public WindowHandle()
: this(true)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="WindowHandle"/> class.
/// </summary>
/// <param name="ownsHandle">Value indicating if this safe handle is responsible for releasing the provided handle.</param>
private WindowHandle(bool ownsHandle)
: base(IntPtr.Zero, ownsHandle)
{ }
/// <summary>
/// Gets a default invalid instance of the <see cref="WindowHandle"/> class.
/// </summary>
public static WindowHandle InvalidHandle
=> new(false);
/// <inheritdoc/>
public override bool IsInvalid
=> handle == IntPtr.Zero;
/// <inheritdoc/>
protected override bool ReleaseHandle()
=> User32.DestroyWindow(handle);
}