-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
214 lines (179 loc) · 6.06 KB
/
Program.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
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
using Microsoft.Win32;
using System;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace TaskBarRenamer
{
internal static class Program
{
#region Fields
public static string Build
{
get
{
return "2024-03-30";
}
}
public static string Website
{
get
{
return "https://kwaschny.net/";
}
}
#endregion
#region Methods
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMain());
}
#region DLLImports
[DllImport("user32")]
public static extern IntPtr GetWindow(
IntPtr hWnd,
int wFlag
);
[DllImport("user32", EntryPoint = "GetClassLong", CharSet = CharSet.Auto)]
public static extern int GetClassLongA(
int hWnd,
int nIndex
);
[DllImport("user32.dll")]
public static extern bool IsWindow(
int hWnd
);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(
int hWnd,
int Msg,
IntPtr wParam,
IntPtr lParam
);
[DllImport("User32.dll")]
public static extern bool IsIconic(
int hWnd
);
[DllImport("User32.dll")]
public static extern Int32 SetForegroundWindow(
int hWnd
);
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(
IntPtr hWnd,
int cmdShow
);
#endregion
private static int ContainsLike(StringCollection stringCollection, string value)
{
for (int i = 0; i < stringCollection.Count; i++)
{
if (stringCollection[i].Contains(value))
return i;
}
return -1;
}
public enum FormOperationResult
{
Successful,
NoEntryFound,
FormIsNull,
FormNotVisible,
FormMinimized,
FormMaximized,
CollectionIsNull,
ValuesCorrupt,
}
public static FormOperationResult SaveForm(Form form, StringCollection formsCollection)
{
if (form == null)
return FormOperationResult.FormIsNull;
if (formsCollection == null)
formsCollection = new StringCollection();
if (!form.Visible)
return FormOperationResult.FormNotVisible;
if (form.WindowState == FormWindowState.Minimized)
return FormOperationResult.FormMinimized;
if (form.WindowState == FormWindowState.Maximized)
return FormOperationResult.FormMaximized;
int index = ContainsLike(formsCollection, form.Name);
if (index >= 0)
formsCollection.RemoveAt(index);
formsCollection.Add(string.Format("{0}|{1}|{2}|{3}|{4}", form.Name, form.Left, form.Top, form.Width, form.Height));
return FormOperationResult.Successful;
}
public static FormOperationResult LoadForm(Form form, StringCollection formsCollection)
{
if (form == null)
return FormOperationResult.FormIsNull;
if (formsCollection == null)
return FormOperationResult.CollectionIsNull;
Rectangle screen = Screen.PrimaryScreen.WorkingArea;
int index = ContainsLike(formsCollection, form.Name);
if (index >= 0)
{
string[] values = formsCollection[index].Split('|');
if (values.Length < 5)
return FormOperationResult.ValuesCorrupt;
int.TryParse(values[1], out int tempValue);
form.Left = tempValue;
int.TryParse(values[2], out tempValue);
form.Top = tempValue;
switch (form.FormBorderStyle)
{
case FormBorderStyle.Sizable:
case FormBorderStyle.SizableToolWindow:
int.TryParse(values[3], out tempValue);
form.Width = tempValue;
int.TryParse(values[4], out tempValue);
form.Height = tempValue;
break;
}
if (form.Left < 0)
form.Left = 0;
if (form.Left + form.Width > screen.Width)
form.Left = screen.Width - form.Width;
if (form.Top < 0)
form.Top = 0;
if (form.Top + form.Height > screen.Height)
form.Top = screen.Height - form.Height;
return FormOperationResult.Successful;
}
else
{
if (form.Owner != null)
{
form.Left = form.Owner.Left + ((form.Owner.Width / 2) - (form.Width / 2));
form.Top = form.Owner.Top + ((form.Owner.Height / 2) - (form.Height / 2));
}
else
{
form.Left = (screen.Width / 2) - (form.Width / 2);
form.Top = (screen.Height / 2) - (form.Height / 2);
}
}
return FormOperationResult.NoEntryFound;
}
public static bool OpenWebsite(string websiteLink)
{
if (string.IsNullOrEmpty(websiteLink))
return false;
try
{
Process.Start(websiteLink);
return true;
}
catch
{
return false;
}
}
#endregion
}
}