Toasts – Diff between revs 7 and 8
?pathlinks?
Rev 7 | Rev 8 | |||
---|---|---|---|---|
Line 3... | Line 3... | |||
3 | // =====COPYRIGHT===== |
3 | // =====COPYRIGHT===== |
|
Line 4... | Line 4... | |||
4 | |
4 | |
|
5 | using System; |
5 | using System; |
|
6 | using System.Collections.Generic; |
6 | using System.Collections.Generic; |
|
- | 7 | using System.Drawing; |
||
- | 8 | using System.IO; |
||
- | 9 | using System.Media; |
||
- | 10 | using System.Reflection; |
||
7 | using System.Drawing; |
11 | using System.Threading.Tasks; |
|
Line 8... | Line 12... | |||
8 | using System.Windows.Forms; |
12 | using System.Windows.Forms; |
|
9 | |
13 | |
|
10 | namespace Toasts |
14 | namespace Toasts |
|
Line 33... | Line 37... | |||
33 | base.Show(); |
37 | base.Show(); |
|
34 | } |
38 | } |
|
Line 35... | Line 39... | |||
35 | |
39 | |
|
Line -... | Line 40... | |||
- | 40 | #endregion |
||
- | 41 | |
||
- | 42 | #region Private Methods |
||
- | 43 | |
||
- | 44 | private static async Task<byte[]> LoadResource(string resource) |
||
- | 45 | { |
||
- | 46 | var assembly = Assembly.GetExecutingAssembly(); |
||
- | 47 | |
||
- | 48 | using (var manifestResourceStream = assembly.GetManifestResourceStream(resource)) |
||
- | 49 | { |
||
- | 50 | if (manifestResourceStream == null) |
||
- | 51 | { |
||
- | 52 | return null; |
||
- | 53 | } |
||
- | 54 | |
||
- | 55 | var memoryStream = new MemoryStream(); |
||
- | 56 | |
||
- | 57 | await manifestResourceStream.CopyToAsync(memoryStream); |
||
- | 58 | |
||
- | 59 | memoryStream.Position = 0L; |
||
- | 60 | |
||
- | 61 | return memoryStream.ToArray(); |
||
- | 62 | } |
||
- | 63 | } |
||
- | 64 | |
||
36 | #endregion |
65 | #endregion |
|
Line 37... | Line 66... | |||
37 | |
66 | |
|
38 | #region Constructors, Destructors and Finalizers |
67 | #region Constructors, Destructors and Finalizers |
|
39 | |
68 | |
|
40 | private ToastForm() |
69 | private ToastForm() |
|
41 | { |
70 | { |
|
42 | InitializeComponent(); |
71 | InitializeComponent(); |
|
43 | } |
72 | } |
|
44 | |
73 | |
|
45 | /// <summary> |
74 | /// <summary> |
|
46 | /// </summary> |
75 | /// </summary> |
|
47 | /// <param name="title"></param> |
76 | /// <param name="title"></param> |
|
48 | /// <param name="body"></param> |
77 | /// <param name="body"></param> |
|
49 | /// <param name="duration"></param> |
78 | /// <param name="duration"></param> |
|
50 | /// <param name="image"></param> |
79 | /// <param name="image"></param> |
|
51 | /// <param name="animation"></param> |
80 | /// <param name="animation"></param> |
|
52 | /// <param name="direction"></param> |
81 | /// <param name="direction"></param> |
|
53 | public ToastForm(string title, string body, int duration, Image logo, Image background, |
82 | public ToastForm(string title, string body, int duration, Image logo, Image background, byte[] sound, |
|
54 | FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction) : this() |
83 | FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction) : this() |
|
55 | { |
84 | { |
|
56 | lifeTimer.Interval = duration; |
85 | lifeTimer.Interval = duration; |
|
57 | labelTitle.Text = title; |
86 | labelTitle.Text = title; |
|
Line -... | Line 87... | |||
- | 87 | labelBody.Text = body; |
||
- | 88 | imageBox.Image = logo; |
||
58 | labelBody.Text = body; |
89 | BackgroundImage = background; |
|
Line 59... | Line 90... | |||
59 | imageBox.Image = logo; |
90 | |
|
60 | BackgroundImage = background; |
91 | _sound = sound; |
|
Line 61... | Line 92... | |||
61 | |
92 | |
|
62 | _animator = new FormAnimator(this, animation, direction, 500); |
93 | _animator = new FormAnimator(this, animation, direction, 500); |
|
63 | |
94 | |
|
64 | Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); |
95 | Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); |
|
65 | } |
96 | } |
|
66 | |
97 | |
|
67 | public ToastForm(string title, string body, int duration, Image logo, |
98 | public ToastForm(string title, string body, int duration, Image logo, byte[] sound, |
|
Line -... | Line 99... | |||
- | 99 | FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction) : this() |
||
- | 100 | { |
||
68 | FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction) : this() |
101 | lifeTimer.Interval = duration; |
|
Line 69... | Line 102... | |||
69 | { |
102 | labelTitle.Text = title; |
|
70 | lifeTimer.Interval = duration; |
103 | labelBody.Text = body; |
|
Line 71... | Line 104... | |||
71 | labelTitle.Text = title; |
104 | imageBox.Image = logo; |
|
72 | labelBody.Text = body; |
105 | |
|
73 | imageBox.Image = logo; |
106 | _sound = sound; |
|
74 | |
107 | |
|
75 | _animator = new FormAnimator(this, animation, direction, 500); |
108 | _animator = new FormAnimator(this, animation, direction, 500); |
|
76 | |
109 | |
|
Line -... | Line 110... | |||
- | 110 | Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); |
||
- | 111 | } |
||
77 | Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); |
112 | |
|
78 | } |
113 | public ToastForm(string title, string body, int duration, Image logo, byte[] sound) : this() |
|
Line 79... | Line 114... | |||
79 | |
114 | { |
|
80 | public ToastForm(string title, string body, int duration, Image logo) : this() |
115 | lifeTimer.Interval = duration; |
|
Line 111... | Line 146... | |||
111 | |
146 | |
|
Line 112... | Line 147... | |||
112 | private bool _allowFocus; |
147 | private bool _allowFocus; |
|
Line -... | Line 148... | |||
- | 148 | |
||
- | 149 | private IntPtr _currentForegroundWindow; |
||
113 | |
150 | |
|
Line 114... | Line 151... | |||
114 | private IntPtr _currentForegroundWindow; |
151 | private byte[] _sound; |
|
Line 115... | Line 152... | |||
115 | |
152 | |
|
116 | #endregion |
153 | #endregion |
|
- | 154 | |
||
- | 155 | #region Event Handlers |
||
- | 156 | |
||
- | 157 | private async void Notification_Load(object sender, EventArgs e) |
||
- | 158 | { |
||
- | 159 | // Play the sound. |
||
- | 160 | if (_sound == null) |
||
- | 161 | { |
||
- | 162 | _sound = await LoadResource($"Toasts.Sounds.default.wav"); |
||
- | 163 | } |
||
- | 164 | |
||
- | 165 | using (var memoryStream = new MemoryStream(_sound)) |
||
- | 166 | { |
||
- | 167 | using (var player = new SoundPlayer(memoryStream)) |
||
117 | |
168 | { |
|
118 | #region Event Handlers |
169 | player.Play(); |
|
119 | |
170 | } |
|
Line 120... | Line 171... | |||
120 | private void Notification_Load(object sender, EventArgs e) |
171 | } |