/
MainWindow.xaml.cs
89 lines (76 loc) · 2.93 KB
/
MainWindow.xaml.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
78
79
80
81
82
83
84
85
86
87
88
89
using FirstFloor.ModernUI.Windows.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Interop;
namespace ProcessRecorder
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : ModernWindow
{
private NotifyIcon n;
public MainWindow()
{
InitializeComponent();
CreateNotifyicon();
}
private void CreateNotifyicon()
{
Container components = new Container();
System.Windows.Forms.ContextMenu contextMenu1 = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem menuItem1 = new System.Windows.Forms.MenuItem();
System.Windows.Forms.MenuItem menuItemSettings = new System.Windows.Forms.MenuItem();
menuItem1.Text = "Exit";
menuItem1.Click += new EventHandler(MenuItem1_Click);
menuItemSettings.Index = 0;
menuItemSettings.Text = "Settings";
menuItemSettings.Click += new EventHandler(SettingsMenuItemClick);
contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { menuItemSettings, menuItem1 });
n = new NotifyIcon(components);
n.BalloonTipText = "MacroPath is working now in background.";
n.ContextMenu = contextMenu1;
n.Text = "MacroPath v.1.1";
n.Visible = true;
n.Icon = new Icon(SystemIcons.Information, 40, 40);
n.Click += new EventHandler(NotifyIcon1_Click);
}
private void NotifyIcon1_Click(object Sender, EventArgs e)
{
System.Windows.Forms.MouseEventArgs m = (System.Windows.Forms.MouseEventArgs)e;
if (m.Button == MouseButtons.Left)
{
Win32.User.Window.SetForegroundWindow(new WindowInteropHelper(this).Handle);
this.WindowState = WindowState.Normal;
}
}
private void MenuItem1_Click(object Sender, EventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
private void SettingsMenuItemClick(object sender, EventArgs e)
{
Win32.User.Window.SetForegroundWindow(new WindowInteropHelper(this).Handle);
this.WindowState = WindowState.Normal;
}
private void MainWndStateChanged(object sender, EventArgs e)
{
switch (WindowState) {
case WindowState.Minimized:
this.ShowInTaskbar = false;
n.Visible = true;
n.ShowBalloonTip(500);
break;
case WindowState.Normal:
this.ShowInTaskbar = true;
n.Visible = false;
break;
}
}
}
}