-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmMain.vb
More file actions
433 lines (349 loc) · 17.9 KB
/
frmMain.vb
File metadata and controls
433 lines (349 loc) · 17.9 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
Imports System.Net.WebRequestMethods
Imports MessengerAPI
Imports MessengerContentInstallerLibrary
Public Class frmMain
Shared api As New Messenger
Shared process As Process
Private disconnectedIcon As Icon
Private awayIcon As Icon
Private busyIcon As Icon
Private invisibleIcon As Icon
Private onlineIcon As Icon
Private wlmIcon As Icon
Private Function MessengerRunning() As Boolean
Try
' process = System.Diagnostics.Process.GetProcessesByName("msnmsgr")(0)
api = New Messenger
modWinman.HideHiddenWindow()
Dim window = api.Window
Return True
Catch ext As System.Runtime.InteropServices.COMException
Return False
Catch ex As IndexOutOfRangeException
Return False
End Try
End Function
Private Sub StartMessenger()
If Not MessengerRunning() Then
process = Process.Start("msnmsgr")
End If
End Sub
Private Function Window() As IMessengerWindow
Return api.Window
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim w As IMessengerWindow = api.Window
w.Show()
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim w As IMessengerWindow = api.Window
w.Close()
End Sub
Private enrolledAutomaticStartup As Boolean
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Hide()
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
enrolledAutomaticStartup = key.GetValueNames.Contains(Application.ProductName) ' for start with windows menu item
process = System.Diagnostics.Process.GetProcessesByName("msnmsgr")(0)
disconnectedIcon = Icon.FromHandle(My.Resources.disconnected.GetHicon())
awayIcon = Icon.FromHandle(My.Resources.away.GetHicon())
busyIcon = Icon.FromHandle(My.Resources.busy.GetHicon())
invisibleIcon = Icon.FromHandle(My.Resources.offline.GetHicon())
onlineIcon = Icon.FromHandle(My.Resources.online.GetHicon())
wlmIcon = Icon.FromHandle(My.Resources.wlm.GetHicon())
'SetIconFromImage(My.Resources.disconnected)
NotifyIcon1.Icon = disconnectedIcon
RefreshContextStatus()
'For Each c As IMessengerContact In api.MyContacts
' ListBox1.Items.Add(c.FriendlyName)
'Next
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
PropertyGrid1.SelectedObject = api
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim contact As IMessengerContact = api.MyContacts(ListBox1.SelectedIndex)
PropertyGrid1.SelectedObject = contact
End Sub
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
Dim contact As IMessengerContact = api.MyContacts(ListBox1.SelectedIndex)
api.InstantMessage(contact)
End Sub
Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
Dim contact As IMessengerContact = api.MyContacts(ListBox1.SelectedIndex)
'api.Page(contact)
End Sub
Private away_statuses() As MISTATUS = {MISTATUS.MISTATUS_AWAY, MISTATUS.MISTATUS_BE_RIGHT_BACK, MISTATUS.MISTATUS_IDLE}
Private busy_statuses() As MISTATUS = {MISTATUS.MISTATUS_BUSY, MISTATUS.MISTATUS_ON_THE_PHONE}
Private offline_statuses() As MISTATUS = {MISTATUS.MISTATUS_OFFLINE, MISTATUS.MISTATUS_UNKNOWN}
Private Function CheckStatus(status As String)
Dim state As MISTATUS
If Not MessengerRunning() Then
' Messenger is not open!
'SetIconFromImage(My.Resources.wlm)
NotifyIcon1.Icon = wlmIcon
SetNotifyStatus("Start Messenger")
Return False
End If
state = api.MyStatus
If status = "online" And state = MISTATUS.MISTATUS_ONLINE Then
NotifyIcon1.Icon = onlineIcon
SetNotifyStatus("Online")
Return True
End If
If status = "away" And away_statuses.Contains(state) Then
NotifyIcon1.Icon = awayIcon
SetNotifyStatus("Away")
Return True
End If
If status = "busy" And busy_statuses.Contains(state) Then
NotifyIcon1.Icon = busyIcon
SetNotifyStatus("Busy")
Return True
End If
If status = "invisible" And state = MISTATUS.MISTATUS_INVISIBLE Then
NotifyIcon1.Icon = invisibleIcon
SetNotifyStatus("Invisible")
Return True
End If
If status = "offline" And offline_statuses.Contains(state) Then
NotifyIcon1.Icon = disconnectedIcon
SetNotifyStatus("Disconnected")
Return True
End If
Return False
End Function
Private Sub ChangeStatus(status As MISTATUS)
api.MyStatus = status
RefreshContextStatus()
End Sub
Private Sub RefreshContextStatus()
Dim ready = MessengerRunning()
QuitMessengerToolStripMenuItem1.Enabled = ready
SignInToolStripMenuItem.Enabled = CheckStatus("offline")
SignOuitToolStripMenuItem.Enabled = ready And Not CheckStatus("offline")
itmOnline.Checked = CheckStatus("online")
itmAway.Checked = CheckStatus("away")
itmBusy.Checked = CheckStatus("busy")
imInvisible.Checked = CheckStatus("invisible")
itmOnline.Enabled = ready And Not CheckStatus("offline")
itmAway.Enabled = ready And Not CheckStatus("offline")
itmBusy.Enabled = ready And Not CheckStatus("offline")
imInvisible.Enabled = ready And Not CheckStatus("offline")
End Sub
Private Sub SetupContextImages()
itmOnline.Image = My.Resources.online_state
itmAway.Image = My.Resources.away_state
itmBusy.Image = My.Resources.busy_state
imInvisible.Image = My.Resources.offline_state
End Sub
Private Sub ContextMenuStrip1_Opened(sender As System.Object, e As System.EventArgs) Handles ContextMenuStrip1.Opening
RefreshContextStatus()
SetupContextImages()
End Sub
Private Sub QuitMessengerToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs)
modWinman.CloseHiddenWindow()
process = System.Diagnostics.Process.GetProcessesByName("msnmsgr")(0)
process.Kill()
End Sub
Private Sub OpenMessenegrToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs)
Window.Show()
End Sub
Private Sub StopMessenger()
For Each process As Process In System.Diagnostics.Process.GetProcessesByName("msnmsgr")
process.Kill()
Next
NotifyIcon1.Icon = wlmIcon
SetNotifyStatus("Start Messenger")
End Sub
Private Sub QuitMessengerToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles QuitMessengerToolStripMenuItem1.Click
StopMessenger()
End Sub
Private Sub NotifyIcon1_DoubleClick(sender As System.Object, e As System.EventArgs) Handles NotifyIcon1.DoubleClick
If MessengerRunning() Then
If Window.IsClosed Then
Window.Show()
Else
Window.Close()
End If
Else
StartMessenger()
End If
End Sub
Private Sub itmOnline_Click(sender As System.Object, e As System.EventArgs) Handles itmOnline.Click
ChangeStatus(MISTATUS.MISTATUS_ONLINE)
End Sub
Private Sub itmAway_Click(sender As System.Object, e As System.EventArgs) Handles itmAway.Click
ChangeStatus(MISTATUS.MISTATUS_AWAY)
End Sub
Private Sub itmBusy_Click(sender As System.Object, e As System.EventArgs) Handles itmBusy.Click
ChangeStatus(MISTATUS.MISTATUS_BUSY)
End Sub
Private Sub imInvisible_Click(sender As System.Object, e As System.EventArgs) Handles imInvisible.Click
ChangeStatus(MISTATUS.MISTATUS_INVISIBLE)
End Sub
Private Sub SetNotifyStatus(p1 As String)
NotifyIcon1.Text = Me.Text & " - " & p1
End Sub
Private Sub SignOuitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SignOuitToolStripMenuItem.Click
api.Signout()
End Sub
Private Sub SignInToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SignInToolStripMenuItem.Click
Window.Show()
End Sub
Private Sub OpenMessengerToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenMessengerToolStripMenuItem.Click
If MessengerRunning() Then
Window.Show()
Else
StartMessenger()
End If
End Sub
Private Sub QuitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles QuitToolStripMenuItem.Click
StopMessenger()
Me.Close()
End Sub
Private Sub GToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles GToolStripMenuItem.Click
modWinman.ShowHiddenWindow()
Me.Close()
End Sub
Private Sub SetStatusToolStripMenuItem1_DropDownOpening(sender As System.Object, e As System.EventArgs) Handles SetStatusToolStripMenuItem1.DropDownOpening
' Clear existing items in the dropdown menu
SetStatusToolStripMenuItem1.DropDownItems.Clear()
SetStatusToolStripMenuItem1.DropDownItems.Add(MusicToolStripMenuItem)
SetStatusToolStripMenuItem1.DropDownItems.Add(GameToolStripMenuItem)
SetStatusToolStripMenuItem1.DropDownItems.Add(OfficeToolStripMenuItem)
SetStatusToolStripMenuItem1.DropDownItems.Add(ToolStripSeparator6)
' Get all running processes
Dim processes() As Process = Process.GetProcesses()
Dim blocked_processes() As String = {"msnmsgr", "TextInputHost"}
' Loop through each process
For Each process As Process In processes
' Check if the process has a main window title
If Not String.IsNullOrEmpty(process.MainWindowTitle) Then
' Create a new dropdown item
Dim newItem As New ToolStripMenuItem()
' Set the text of the dropdown item to the window title
newItem.Text = process.MainWindowTitle
' Set the tag of the dropdown item to the process name
newItem.Tag = process.ProcessName
If newItem.Tag = monitoredProcess And beamingActivity Then
newItem.Checked = True
End If
Try
newItem.Image = Icon.ExtractAssociatedIcon(process.Modules(0).FileName).ToBitmap()
Catch ex As Exception
End Try
' Add a click event handler to the dropdown item
AddHandler newItem.Click, AddressOf ToolStripMenuItem_Click
' Add the dropdown item to the menu
SetStatusToolStripMenuItem1.DropDownItems.Add(newItem)
End If
Next
End Sub
Private beamingActivity As Boolean = False
Private monitoredProcess = ""
Private activityKind = "Music"
Private Sub ToolStripMenuItem_Click(sender As Object, e As EventArgs)
' Handle the click event here
Dim clickedItem As ToolStripMenuItem = DirectCast(sender, ToolStripMenuItem)
' Access the process name from the Tag property
Dim processName As String = clickedItem.Tag.ToString()
monitoredProcess = clickedItem.Tag.ToString()
beamingActivity = True
updateActivity()
'modWinman.setActivity("Music", clickedItem.Text)
' You can use the processName as needed (e.g., launch another process, etc.)
'MessageBox.Show("Selected Process: " & processName)
' Add a click event handler to the dropdown item
'AddHandler music.Click, AddressOf ToolStripMenuItem_Click
'AddHandler game.Click, AddressOf ToolStripMenuItem_Click
'AddHandler office.Click, AddressOf ToolStripMenuItem_Click
'clickedItem.DropDownItems.Add(music)
'clickedItem.DropDownItems.Add(game)
'clickedItem.DropDownItems.Add(office)
End Sub
Private Sub updateActivity()
Dim activity As MessengerDotNet.MessengerActivityType = MessengerDotNet.MessengerActivityType.Music
If activityKind = "Games" Then
activity = MessengerDotNet.MessengerActivityType.Games
ElseIf activityKind = "Office" Then
activity = MessengerDotNet.MessengerActivityType.Office
End If
Dim procs = Process.GetProcessesByName(monitoredProcess)
If procs.Count > 0 And beamingActivity Then
Dim proc As Process = procs(0)
MessengerDotNet.MessengerActivity.SetActivity(activity, proc.MainWindowTitle)
Else
MessengerDotNet.MessengerActivity.SetActivity(MessengerDotNet.MessengerActivityType.Music, "")
End If
Timer1.Enabled = beamingActivity
End Sub
Private Sub MusicToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles MusicToolStripMenuItem.Click
activityKind = "Music"
updateActivity()
End Sub
Private Sub GameToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles GameToolStripMenuItem.Click
activityKind = "Games"
updateActivity()
End Sub
Private Sub OfficeToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OfficeToolStripMenuItem.Click
activityKind = "Office"
updateActivity()
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = beamingActivity
updateActivity()
End Sub
Private Sub Timer2_Tick(sender As System.Object, e As System.EventArgs) Handles Timer2.Tick
RefreshContextStatus()
End Sub
Private Sub ReceivedFilesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ReceivedFilesToolStripMenuItem.Click
Dim folder As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\My Received Files\"
If My.Computer.FileSystem.DirectoryExists(folder) Then
Process.Start(folder)
Else
MsgBox("Unable to start folder " & folder & ", as it does not exist", MsgBoxStyle.Information, "Unable to browse")
End If
End Sub
Private Sub DdToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DdToolStripMenuItem.Click
Dim folder As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\Microsoft\Messenger"
If My.Computer.FileSystem.DirectoryExists(folder) Then
Process.Start(folder)
Else
MsgBox("Unable to start folder " & folder & ", as it does not exist", MsgBoxStyle.Information, "Unable to browse")
End If
End Sub
Private Sub CrosstalkToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CrosstalkToolStripMenuItem.Click
Process.Start("https://crosstalk.im/")
End Sub
Private Sub EscargotchatToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EscargotchatToolStripMenuItem.Click
Process.Start("https://escargot.chat/")
End Sub
Private Sub TrayGitHubToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TrayGitHubToolStripMenuItem.Click
Process.Start("https://github.com/dotcomboom/09tray")
End Sub
Private Sub Start09trayWithWindowsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles Start09trayWithWindowsToolStripMenuItem.Click
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
If key.GetValueNames.Contains(Application.ProductName) Then
key.DeleteValue(Application.ProductName)
MsgBox("Unregistered 09tray from automatic startup for your user." & vbNewLine & "Make sure to check if your Windows Live Messenger startup options are as you would like.", MsgBoxStyle.Information, "Startup")
enrolledAutomaticStartup = False
Else
key.SetValue(Application.ProductName, Application.ExecutablePath)
MsgBox("Registered 09tray to automatic startup for your user." & vbNewLine & "Double-click the 09tray icon to start Messenger, if it isn't set to automatically start.", MsgBoxStyle.Information, "Startup")
enrolledAutomaticStartup = True
End If
End Sub
Private Sub About09trayToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles About09trayToolStripMenuItem.Click
MsgBox(Application.ProductName & " " & Application.ProductVersion & vbNewLine &
"Notification area icon for Windows Live Messenger 2009 on Windows 7 and later", MsgBoxStyle.OkOnly, "About " & Application.ProductName)
End Sub
Private Sub ActivityBroadcastToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ActivityBroadcastToolStripMenuItem.Click
beamingActivity = Not beamingActivity
updateActivity()
End Sub
Private Sub TidyWLMToolStripMenuItem_DropDownOpening(sender As Object, e As EventArgs) Handles TidyWLMToolStripMenuItem.DropDownOpening
ActivityBroadcastToolStripMenuItem.Checked = beamingActivity
Start09trayWithWindowsToolStripMenuItem.Checked = enrolledAutomaticStartup
End Sub
End Class