-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmMain.vb
107 lines (89 loc) · 4.14 KB
/
frmMain.vb
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Public Class frmMain
Private m_clsMouseHook As MouseHook = New MouseHook
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_clsMouseHook.HookMouse()
cmsTray.Renderer = New ToolStripProfessionalRenderer(New ThemedColorTable)
If WinUsingDarkTheme() Then ThemedColorTable.darkMode = True
cmsTray.ForeColor = If(ThemedColorTable.darkMode, Color.White, Color.Black)
End Sub
Public Function WinUsingDarkTheme() As Boolean
Using key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Themes\Personalize")
Dim value = key?.GetValue("AppsUseLightTheme")
If value IsNot Nothing AndAlso value = 0 Then
Return True
End If
End Using
Return False
End Function
Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
m_clsMouseHook.UnhookMouse()
End Sub
Protected Overrides ReadOnly Property CreateParams As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or WindowStyles.WS_MINIMIZE Xor WindowStyles.WS_VISIBLE
cp.ExStyle = cp.ExStyle Or WindowStylesEx.WS_EX_TOOLWINDOW
'cp.ClassStyle = cp.ClassStyle
Return cp
End Get
End Property
Private themechanging As Boolean = False
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case WM_DWMCOLORIZATIONCOLORCHANGED
If Not themechanging Then
themechanging = True
ThemedColorTable.darkMode = WinUsingDarkTheme()
cmsTray.ForeColor = If(ThemedColorTable.darkMode, Color.White, Color.Black)
Task.Run(Sub()
Threading.Thread.Sleep(7500)
themechanging = False
End Sub)
End If
End Select
MyBase.WndProc(m)
End Sub
Protected Overloads Overrides ReadOnly Property ShowWithoutActivation() As Boolean
Get
Return True
End Get
End Property
Private wolfProc As Process
Private Sub tmrTick_Tick(sender As Object, e As EventArgs) Handles tmrTick.Tick
Try 'We try here since Process.HasExited() will except when Process is elevated
Dim hwnd = IntPtr.Zero
If wolfProc Is Nothing OrElse wolfProc.HasExited() Then
For Each pp As Process In Process.GetProcessesByName("WolfNewOrder_x64") _
.Concat(Process.GetProcessesByName("WolfOldBlood_x64")) _
.Concat(Process.GetProcessesByName("NewColossus_x64vk")) _
.Concat(Process.GetProcessesByName("Youngblood_x64vk"))
If pp.MainWindowTitle.StartsWith("Wolfenstein") Then
hwnd = pp.MainWindowHandle
wolfProc = pp
Exit For
End If
Next
Else
hwnd = wolfProc.MainWindowHandle
End If
If hwnd <> IntPtr.Zero Then
wolfProc.Refresh()
If Not wolfProc.MainWindowTitle.StartsWith("Wolfenstein") Then 'sysmenu is open
'Todo: find a way to display cursor when sysmenu is opened from taskbar, showcursor doesn't work, maybe use a fake cursor?
hwnd = IntPtr.Zero
End If
End If
If hwnd <> IntPtr.Zero Then
GetClientRect(hwnd, m_clsMouseHook.rcC) 'update clipping bounds
End If
m_clsMouseHook.hwnd = hwnd
Catch ex As Exception
Debug.Print($"Exeption {ex.Message}")
wolfProc = Nothing
m_clsMouseHook.hwnd = IntPtr.Zero
End Try
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
End Class