-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
107 lines (95 loc) · 3.57 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
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace ProgressBarSrc
{
internal static class Program
{
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(IntPtr handle);
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
/*foreach (var item in args)
{
MessageBox.Show(item);
}*/
if (args.Length != 0)
{
switch (args[0].ToUpper())
{
case "-S":
case "/S":
Application.Run(new ScreenSaverForm());
return;
case "-P":
case "/P":
if (args.Length < 2) return;
if (!int.TryParse(args[1], out int result)) return;
IntPtr handle = new IntPtr(result);
Application.Run(new ScreenSaverForm(handle));
return;
}
if (!args[0].ToUpper().StartsWith("/C")) return;
}
Application.Run(new Settings());
}
public class FilesINI
{
string path;
public FilesINI(string path)
{ this.path = path; }
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key,
string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def,
StringBuilder retVal, int size, string filePath);
public void Write(string key, string section, string value)
{
WritePrivateProfileString(section, key, value, path);
}
public string Read(string key, string section)
{
StringBuilder temp = new StringBuilder(255);
GetPrivateProfileString(section, key, "", temp, 255, path);
return temp.ToString();
}
public string Read(string key, string section, string Default)
{
StringBuilder temp = new StringBuilder(255);
GetPrivateProfileString(section, key, Default, temp, 255, path);
return temp.ToString();
}
public int ReadInteger(string key, string section, int Default)
{
string str = Read(key, section);
try
{ return int.Parse(str); }
catch
{
if (!string.IsNullOrEmpty(str) && str.ToLower() != "default") MessageBox.Show("\"" + str + "\" is not a valid integer for " + key, "Error");
return Default;
}
}
public double ReadDouble(string key, string section, double Default)
{
string str = Read(key, section);
try
{ return double.Parse(str); }
catch
{
if (!string.IsNullOrEmpty(str) && str.ToLower() != "default") MessageBox.Show("\"" + str + "\" is not a valid value for " + key, "Error");
return Default;
}
}
}
}
}