Skip to content

Commit 2e33c4d

Browse files
committed
update
1 parent 4d4f714 commit 2e33c4d

File tree

12 files changed

+713
-26
lines changed

12 files changed

+713
-26
lines changed

TCSetup/TCSetup.vdproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@
171171
"Product"
172172
{
173173
"Name" = "8:Microsoft Visual Studio"
174-
"ProductName" = "8:TCSetup"
175-
"ProductCode" = "8:{7738777E-2FF0-4D73-BA7F-CE5C4F8C09AF}"
176-
"PackageCode" = "8:{85FC3FD2-AC7A-4722-8FB3-442D69067E7D}"
174+
"ProductName" = "8:TimeControl"
175+
"ProductCode" = "8:{2BC11DA4-CD84-437D-A082-79AFF40F938A}"
176+
"PackageCode" = "8:{4758052E-E293-4206-9BC6-5FE53A2FD9B8}"
177177
"UpgradeCode" = "8:{A7DC5BC4-7E3E-4B58-A0AD-3C9AC9F873C1}"
178178
"AspNetVersion" = "8:4.0.30319.0"
179179
"RestartWWWService" = "11:FALSE"
180-
"RemovePreviousVersions" = "11:FALSE"
180+
"RemovePreviousVersions" = "11:TRUE"
181181
"DetectNewerInstalledVersion" = "11:TRUE"
182182
"InstallAllUsers" = "11:FALSE"
183-
"ProductVersion" = "8:2.0.1"
184-
"Manufacturer" = "8:Default Company Name"
183+
"ProductVersion" = "8:3.0.0"
184+
"Manufacturer" = "8:SamHou"
185185
"ARPHELPTELEPHONE" = "8:"
186186
"ARPHELPLINK" = "8:"
187187
"Title" = "8:TCSetup"
@@ -722,7 +722,7 @@
722722
{
723723
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B7C31D1C4E42443D89CA87F9596A43B7"
724724
{
725-
"SourcePath" = "8:..\\TimeControl\\obj\\Release\\net5.0-windows\\apphost.exe"
725+
"SourcePath" = "8:..\\TimeControl\\obj\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
726726
"TargetName" = "8:"
727727
"Tag" = "8:"
728728
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"

TimeControl/App.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TimeControl
8+
{
9+
internal class App
10+
{
11+
private string name;
12+
private string location;
13+
public string Name { get { return name; }}
14+
private int time;
15+
16+
public string ReportApp()
17+
{
18+
return Name + " 已使用 " + time+" 秒!";
19+
}
20+
public App(string name, string location)
21+
{
22+
this.name = name;
23+
this.location = location;
24+
time = 0;
25+
}
26+
public void Run()
27+
{
28+
time++;
29+
}
30+
}
31+
}

TimeControl/ControlPanel.Designer.cs

Lines changed: 148 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TimeControl/ControlPanel.cs

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
using System.Threading.Tasks;
99
using System.Windows.Forms;
1010
using System.Runtime.InteropServices;
11+
using System.Diagnostics;
12+
using System.Threading;
1113

1214
namespace TimeControl
1315
{
1416
public partial class ControlPanel : Form
1517
{
18+
bool closable = false;
19+
List<App> appList = new List<App>();
1620
#region Dllimport
1721

1822
[Flags]
@@ -116,21 +120,85 @@ public ControlPanel()
116120

117121
private void startButton_Click(object sender, EventArgs e)
118122
{
119-
if (unlockPasswordBox.Text=="")
120-
{
121-
122-
}
123123
IntPtr nowDesktop = GetThreadDesktop(GetCurrentThreadId());
124124
IntPtr newDesktop = CreateDesktop("Lock", null, null, 0, ACCESS_MASK.GENERIC_ALL, IntPtr.Zero);
125125
SwitchDesktop(newDesktop);
126126
System.Threading.Tasks.Task.Factory.StartNew(() =>
127127
{
128128
SetThreadDesktop(newDesktop);
129-
Lock _lock = new Lock(Convert.ToInt32(timeBox.Value),unlockPasswordBox.Text);
129+
Lock _lock = new Lock(Convert.ToInt32(timeBox.Value), unlockPasswordBox.Text);
130130
Application.Run(_lock);
131131
}).Wait();
132132
SwitchDesktop(nowDesktop);
133133
CloseDesktop(newDesktop);
134134
}
135+
136+
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
137+
{
138+
Show();
139+
}
140+
141+
private void ControlPanel_FormClosing(object sender, FormClosingEventArgs e)
142+
{
143+
if (!closable)
144+
{
145+
e.Cancel = true;
146+
Hide();
147+
}
148+
}
149+
150+
private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
151+
{
152+
closable = true;
153+
Close();
154+
}
155+
156+
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
157+
{
158+
Process.Start("explorer.exe", "https://icons8.com/icon/19614/icon");
159+
}
160+
161+
private void backgroundProcessMonitor_DoWork(object sender, DoWorkEventArgs e)
162+
{
163+
while (true)
164+
{
165+
foreach (App app in appList)//计算进程时间
166+
{
167+
if (Process.GetProcessesByName(app.Name).Length != 0)
168+
{ app.Run(); }
169+
}
170+
Thread.Sleep(1000);
171+
}
172+
}
173+
174+
private void ControlPanel_Load(object sender, EventArgs e)
175+
{
176+
backgroundProcessMonitor.RunWorkerAsync();
177+
}
178+
179+
private void appAddButton_Click(object sender, EventArgs e)//添加打开的窗口
180+
{
181+
appList.Clear();
182+
Process[] processes = Process.GetProcesses();
183+
foreach (Process process in processes)
184+
{
185+
if (!string.IsNullOrEmpty(process.MainWindowTitle))
186+
{
187+
appList.Add(new App(process.ProcessName, process.MainModule.FileName));
188+
}
189+
}
190+
ListBoxController.Refresh(usageBox, appList);
191+
}
192+
193+
private void removeButton_Click(object sender, EventArgs e)//移除所有的已添加窗口
194+
{
195+
appList.Clear();
196+
ListBoxController.Refresh(usageBox, appList);
197+
}
198+
199+
private void refreshButton_Click(object sender, EventArgs e)//重新获取所有软件所用时间
200+
{
201+
ListBoxController.Refresh(usageBox, appList);
202+
}
135203
}
136204
}

0 commit comments

Comments
 (0)