-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProcessIcon.cs
77 lines (70 loc) · 2.56 KB
/
ProcessIcon.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
66
67
68
69
70
71
72
73
74
75
76
77
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
using System;
using System.Reflection;
using System.Windows.Forms;
using TrayApp.Properties;
namespace TrayApp
{
/// <summary>
///
/// </summary>
internal class ProcessIcon : IDisposable
{
/// <summary>
/// The NotifyIcon object.
/// </summary>
public static NotifyIcon ni;
/// <summary>
/// Initializes a new instance of the <see cref="ProcessIcon"/> class.
/// </summary>
public ProcessIcon()
{
// Instantiate the NotifyIcon object.
ni = new NotifyIcon();
}
/// <summary>
/// Displays the icon in the system tray.
/// </summary>
public void Display()
{
// Put the icon in the system tray and allow it react to mouse clicks.
ni.MouseClick += new MouseEventHandler(ni_MouseClick);
ni.Icon = Resources.TrayReader;
ni.Text = "TrayReader";
ni.Visible = true;
// Attach a context menu.
//ni.ContextMenuStrip = new ContextMenus().Create();
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
public void Dispose()
{
// When the application closes, this will remove the icon from the system tray immediately.
ni.Dispose();
}
/// <summary>
/// Handles the MouseClick event of the ni control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
private void ni_MouseClick(object sender, MouseEventArgs e)
{
MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
// Handle mouse button clicks.
if (e.Button == MouseButtons.Left)
{
ni.ContextMenuStrip = new ContextMenus().CreateLoadingMenu();
mi.Invoke(ni, null);
ni.ContextMenuStrip = new ContextMenus().CreateFeedsMenu(false);
mi.Invoke(ni, null);
}
else if (e.Button == MouseButtons.Right)
{
ni.ContextMenuStrip = new ContextMenus().CreateOptionsMenu();
mi.Invoke(ni, null);
}
}
}
}