@@ -10,6 +10,11 @@ public unsafe partial struct HRGN : IDisposable
10
10
{
11
11
public void Dispose ( )
12
12
{
13
+ if ( IsFull )
14
+ {
15
+ return ;
16
+ }
17
+
13
18
if ( ! IsNull )
14
19
{
15
20
Interop . DeleteObject ( this ) ;
@@ -18,6 +23,18 @@ public void Dispose()
18
23
Unsafe . AsRef ( in this ) = default ;
19
24
}
20
25
26
+ /// <summary>
27
+ /// Special <see cref="HRGN"/> sent during WM_NCPAINT to indicate the entire window.
28
+ /// </summary>
29
+ public static HRGN Full { get ; } = ( HRGN ) 1 ;
30
+
31
+ /// <summary>
32
+ /// Is special <see cref="HRGN.Full"/> value.
33
+ /// </summary>
34
+ public bool IsFull => Value == Full . Value ;
35
+
36
+ // There is also a special HRGN_MONITOR (2) that is used when maximized. Not sure if this escapes.
37
+
21
38
public static HRGN FromRectangle ( Rectangle rectangle ) =>
22
39
Interop . CreateRectRgn ( rectangle . X , rectangle . Y , rectangle . Right , rectangle . Bottom ) ;
23
40
@@ -30,13 +47,27 @@ public static HRGN FromEllipse(Rectangle bounds) =>
30
47
31
48
public static HRGN CreateEmpty ( ) => Interop . CreateRectRgn ( 0 , 0 , 0 , 0 ) ;
32
49
33
- public static HRGN CombineRegion ( HRGN first , HRGN second , RegionCombineMode combineMode ) =>
34
- CombineRegion ( first , second , combineMode , out _ ) ;
50
+ public HRGN Combine ( HRGN region , RegionCombineMode combineMode ) =>
51
+ Combine ( region , combineMode , out _ ) ;
52
+
53
+ public HRGN Combine ( HRGN region , RegionCombineMode combineMode , out RegionType type )
54
+ {
55
+ HRGN hrgn = CreateEmpty ( ) ;
56
+ type = ( RegionType ) Interop . CombineRgn ( hrgn , this , region , ( RGN_COMBINE_MODE ) combineMode ) ;
57
+ if ( type == RegionType . Error )
58
+ {
59
+ hrgn . Dispose ( ) ;
60
+ }
61
+
62
+ return hrgn ;
63
+ }
64
+
65
+ public HRGN Copy ( ) => Copy ( out _ ) ;
35
66
36
- public static HRGN CombineRegion ( HRGN first , HRGN second , RegionCombineMode combineMode , out RegionType type )
67
+ public HRGN Copy ( out RegionType type )
37
68
{
38
69
HRGN hrgn = CreateEmpty ( ) ;
39
- type = ( RegionType ) Interop . CombineRgn ( hrgn , first , second , ( RGN_COMBINE_MODE ) combineMode ) ;
70
+ type = ( RegionType ) Interop . CombineRgn ( hrgn , this , default , ( RGN_COMBINE_MODE ) RegionCombineMode . Copy ) ;
40
71
if ( type == RegionType . Error )
41
72
{
42
73
hrgn . Dispose ( ) ;
0 commit comments