Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MainWindowFinder.cs
Go to the documentation of this file.
1
using
System.Runtime.CompilerServices
;
2
using
System.Runtime.InteropServices
;
3
4
namespace
System.Diagnostics
;
5
6
internal
struct
MainWindowFinder
7
{
8
private
IntPtr
_bestHandle
;
9
10
private
int
_processId
;
11
12
public
unsafe
static
IntPtr
FindMainWindow
(
int
processId)
13
{
14
Unsafe
.SkipInit(out
MainWindowFinder
mainWindowFinder);
15
mainWindowFinder._bestHandle =
IntPtr
.
Zero
;
16
mainWindowFinder._processId = processId;
17
global::Interop.User32.EnumWindows((delegate* unmanaged<IntPtr, IntPtr, global::Interop.BOOL>)(delegate*<
IntPtr
,
IntPtr
, global::Interop.BOOL>)(&
EnumWindowsCallback
), (
IntPtr
)(&mainWindowFinder));
18
return
mainWindowFinder._bestHandle;
19
}
20
21
private
static
bool
IsMainWindow
(
IntPtr
handle
)
22
{
23
if
(global::Interop.User32.GetWindow(
handle
, 4) ==
IntPtr
.
Zero
)
24
{
25
return
global::Interop.User32.IsWindowVisible(
handle
) != global::Interop.BOOL.FALSE;
26
}
27
return
false
;
28
}
29
30
[UnmanagedCallersOnly]
31
private
unsafe
static
global::Interop.BOOL
EnumWindowsCallback
(
IntPtr
handle
,
IntPtr
extraParameter)
32
{
33
MainWindowFinder
* ptr = (
MainWindowFinder
*)(
void
*)extraParameter;
34
int
num = 0;
35
global::Interop.User32.GetWindowThreadProcessId(
handle
, &num);
36
if
(num == ptr->
_processId
&&
IsMainWindow
(
handle
))
37
{
38
ptr->
_bestHandle
=
handle
;
39
return
global::Interop.BOOL.FALSE;
40
}
41
return
global::Interop.BOOL.TRUE;
42
}
43
}
System.Runtime.CompilerServices.Unsafe
Definition
Unsafe.cs:6
System.Diagnostics
Definition
AggregationManager.cs:6
System.Runtime.CompilerServices
Definition
NullablePublicOnlyAttribute.cs:3
System.Runtime.InteropServices
Definition
SequenceMarshal.cs:4
System.ExceptionArgument.handle
@ handle
System.Diagnostics.MainWindowFinder.FindMainWindow
static unsafe IntPtr FindMainWindow(int processId)
Definition
MainWindowFinder.cs:12
System.Diagnostics.MainWindowFinder.EnumWindowsCallback
static unsafe global::Interop.BOOL EnumWindowsCallback(IntPtr handle, IntPtr extraParameter)
Definition
MainWindowFinder.cs:31
System.Diagnostics.MainWindowFinder._bestHandle
IntPtr _bestHandle
Definition
MainWindowFinder.cs:8
System.Diagnostics.MainWindowFinder.IsMainWindow
static bool IsMainWindow(IntPtr handle)
Definition
MainWindowFinder.cs:21
System.Diagnostics.MainWindowFinder._processId
int _processId
Definition
MainWindowFinder.cs:10
System.Diagnostics.MainWindowFinder
Definition
MainWindowFinder.cs:7
System.IntPtr.Zero
static readonly IntPtr Zero
Definition
IntPtr.cs:18
System.IntPtr
Definition
IntPtr.cs:14
source
System.Diagnostics.Process
System.Diagnostics
MainWindowFinder.cs
Generated by
1.10.0