Skip to content

Commit 3e27b93

Browse files
committed
bug fix
1 parent dd0756d commit 3e27b93

26 files changed

+1367
-933
lines changed

TCSetup/TCSetup.vdproj

Lines changed: 761 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TimeControl/ControlPanel.cs

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
using System.Runtime.InteropServices;
11+
12+
namespace TimeControl
13+
{
14+
public partial class ControlPanel : Form
15+
{
16+
#region Dllimport
17+
18+
[Flags]
19+
public enum ACCESS_MASK : uint
20+
{
21+
DELETE = 0x00010000,
22+
READ_CONTROL = 0x00020000,
23+
WRITE_DAC = 0x00040000,
24+
WRITE_OWNER = 0x00080000,
25+
SYNCHRONIZE = 0x00100000,
26+
27+
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
28+
29+
STANDARD_RIGHTS_READ = 0x00020000,
30+
STANDARD_RIGHTS_WRITE = 0x00020000,
31+
STANDARD_RIGHTS_EXECUTE = 0x00020000,
32+
33+
STANDARD_RIGHTS_ALL = 0x001F0000,
34+
35+
SPECIFIC_RIGHTS_ALL = 0x0000FFFF,
36+
37+
ACCESS_SYSTEM_SECURITY = 0x01000000,
38+
39+
MAXIMUM_ALLOWED = 0x02000000,
40+
41+
GENERIC_READ = 0x80000000,
42+
GENERIC_WRITE = 0x40000000,
43+
GENERIC_EXECUTE = 0x20000000,
44+
GENERIC_ALL = 0x10000000,
45+
46+
DESKTOP_READOBJECTS = 0x00000001,
47+
DESKTOP_CREATEWINDOW = 0x00000002,
48+
DESKTOP_CREATEMENU = 0x00000004,
49+
DESKTOP_HOOKCONTROL = 0x00000008,
50+
DESKTOP_JOURNALRECORD = 0x00000010,
51+
DESKTOP_JOURNALPLAYBACK = 0x00000020,
52+
DESKTOP_ENUMERATE = 0x00000040,
53+
DESKTOP_WRITEOBJECTS = 0x00000080,
54+
DESKTOP_SWITCHDESKTOP = 0x00000100,
55+
56+
WINSTA_ENUMDESKTOPS = 0x00000001,
57+
WINSTA_READATTRIBUTES = 0x00000002,
58+
WINSTA_ACCESSCLIPBOARD = 0x00000004,
59+
WINSTA_CREATEDESKTOP = 0x00000008,
60+
WINSTA_WRITEATTRIBUTES = 0x00000010,
61+
WINSTA_ACCESSGLOBALATOMS = 0x00000020,
62+
WINSTA_EXITWINDOWS = 0x00000040,
63+
WINSTA_ENUMERATE = 0x00000100,
64+
WINSTA_READSCREEN = 0x00000200,
65+
66+
WINSTA_ALL_ACCESS = 0x0000037F
67+
}
68+
69+
[StructLayout(LayoutKind.Sequential)]
70+
public struct SECURITY_ATTRIBUTES
71+
{
72+
public int nLength;
73+
public IntPtr lpSecurityDescriptor;
74+
public int bInheritHandle;
75+
}
76+
77+
[DllImport("kernel32.dll")]
78+
private static extern uint GetCurrentThreadId();
79+
80+
[DllImport("user32.dll", EntryPoint = "CreateDesktop", CharSet = CharSet.Unicode, SetLastError = true)]
81+
public static extern IntPtr CreateDesktop(
82+
[MarshalAs(UnmanagedType.LPWStr)] string desktopName,
83+
[MarshalAs(UnmanagedType.LPWStr)] string device, // must be null.
84+
[MarshalAs(UnmanagedType.LPWStr)] string deviceMode, // must be null,
85+
[MarshalAs(UnmanagedType.U4)] int flags, // use 0
86+
[MarshalAs(UnmanagedType.U4)] ACCESS_MASK accessMask,
87+
[MarshalAs(UnmanagedType.LPStruct)] SECURITY_ATTRIBUTES attributes);
88+
89+
[DllImport("user32.dll", EntryPoint = "CreateDesktop", CharSet = CharSet.Unicode, SetLastError = true)]
90+
public static extern IntPtr CreateDesktop(
91+
[MarshalAs(UnmanagedType.LPWStr)] string desktopName,
92+
[MarshalAs(UnmanagedType.LPWStr)] string device, // must be null.
93+
[MarshalAs(UnmanagedType.LPWStr)] string deviceMode, // must be null,
94+
[MarshalAs(UnmanagedType.U4)] int flags, // use 0
95+
[MarshalAs(UnmanagedType.U4)] ACCESS_MASK accessMask,
96+
IntPtr attributes);
97+
98+
[DllImport("user32.dll", EntryPoint = "CloseDesktop", CharSet = CharSet.Unicode, SetLastError = true)]
99+
[return: MarshalAs(UnmanagedType.Bool)]
100+
public static extern bool CloseDesktop(IntPtr handle);
101+
102+
[DllImport("user32.dll")]
103+
public static extern bool SwitchDesktop(IntPtr hDesktop);
104+
105+
106+
[DllImport("user32.dll", SetLastError = true)]
107+
public static extern bool SetThreadDesktop(IntPtr hDesktop);
108+
109+
[DllImport("user32.dll", SetLastError = true)]
110+
public static extern IntPtr GetThreadDesktop(uint dwThreadId);
111+
#endregion
112+
public ControlPanel()
113+
{
114+
InitializeComponent();
115+
}
116+
117+
private void startButton_Click(object sender, EventArgs e)
118+
{
119+
120+
IntPtr nowDesktop = GetThreadDesktop(GetCurrentThreadId());
121+
IntPtr newDesktop = CreateDesktop("Lock", null, null, 0, ACCESS_MASK.GENERIC_ALL, IntPtr.Zero);
122+
SwitchDesktop(newDesktop);
123+
System.Threading.Tasks.Task.Factory.StartNew(() =>
124+
{
125+
SetThreadDesktop(newDesktop);
126+
Lock _lock = new Lock(Convert.ToInt32(timeBox.Value));
127+
Application.Run(_lock);
128+
}).Wait();
129+
SwitchDesktop(nowDesktop);
130+
CloseDesktop(newDesktop);
131+
}
132+
}
133+
}

TimeControl/ControlPanel.resx

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<root>
2+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
3+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
4+
<xsd:element name="root" msdata:IsDataSet="true">
5+
<xsd:complexType>
6+
<xsd:choice maxOccurs="unbounded">
7+
<xsd:element name="metadata">
8+
<xsd:complexType>
9+
<xsd:sequence>
10+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
11+
</xsd:sequence>
12+
<xsd:attribute name="name" use="required" type="xsd:string" />
13+
<xsd:attribute name="type" type="xsd:string" />
14+
<xsd:attribute name="mimetype" type="xsd:string" />
15+
<xsd:attribute ref="xml:space" />
16+
</xsd:complexType>
17+
</xsd:element>
18+
<xsd:element name="assembly">
19+
<xsd:complexType>
20+
<xsd:attribute name="alias" type="xsd:string" />
21+
<xsd:attribute name="name" type="xsd:string" />
22+
</xsd:complexType>
23+
</xsd:element>
24+
<xsd:element name="data">
25+
<xsd:complexType>
26+
<xsd:sequence>
27+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
28+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
29+
</xsd:sequence>
30+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
31+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
32+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
33+
<xsd:attribute ref="xml:space" />
34+
</xsd:complexType>
35+
</xsd:element>
36+
<xsd:element name="resheader">
37+
<xsd:complexType>
38+
<xsd:sequence>
39+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
40+
</xsd:sequence>
41+
<xsd:attribute name="name" type="xsd:string" use="required" />
42+
</xsd:complexType>
43+
</xsd:element>
44+
</xsd:choice>
45+
</xsd:complexType>
46+
</xsd:element>
47+
</xsd:schema>
48+
<resheader name="resmimetype">
49+
<value>text/microsoft-resx</value>
50+
</resheader>
51+
<resheader name="version">
52+
<value>2.0</value>
53+
</resheader>
54+
<resheader name="reader">
55+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
56+
</resheader>
57+
<resheader name="writer">
58+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
59+
</resheader>
60+
<data name="$this.Text" xml:space="preserve">
61+
<value>ControlPanel</value>
62+
</data>
63+
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
64+
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
65+
<value>9, 20</value>
66+
</data>
67+
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
68+
<data name="timeBox.TabIndex" type="System.Int32, mscorlib">
69+
<value>0</value>
70+
</data>
71+
<data name="startButton.Location" type="System.Drawing.Point, System.Drawing">
72+
<value>247, 245</value>
73+
</data>
74+
<data name="&gt;&gt;startButton.ZOrder" xml:space="preserve">
75+
<value>0</value>
76+
</data>
77+
<data name="timeBox.Location" type="System.Drawing.Point, System.Drawing">
78+
<value>335, 141</value>
79+
</data>
80+
<data name="&gt;&gt;startButton.Type" xml:space="preserve">
81+
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
82+
</data>
83+
<data name="&gt;&gt;$this.Name" xml:space="preserve">
84+
<value>ControlPanel</value>
85+
</data>
86+
<data name="&gt;&gt;timeBox.Type" xml:space="preserve">
87+
<value>System.Windows.Forms.NumericUpDown, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
88+
</data>
89+
<data name="&gt;&gt;timeBox.Name" xml:space="preserve">
90+
<value>timeBox</value>
91+
</data>
92+
<data name="&gt;&gt;startButton.Name" xml:space="preserve">
93+
<value>startButton</value>
94+
</data>
95+
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
96+
<value>800, 450</value>
97+
</data>
98+
<data name="&gt;&gt;timeBox.Parent" xml:space="preserve">
99+
<value>$this</value>
100+
</data>
101+
<data name="&gt;&gt;startButton.Parent" xml:space="preserve">
102+
<value>$this</value>
103+
</data>
104+
<data name="&gt;&gt;timeBox.ZOrder" xml:space="preserve">
105+
<value>1</value>
106+
</data>
107+
<data name="&gt;&gt;$this.Type" xml:space="preserve">
108+
<value>System.Windows.Forms.Form, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
109+
</data>
110+
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
111+
<data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
112+
<value>CenterScreen</value>
113+
</data>
114+
<data name="startButton.TabIndex" type="System.Int32, mscorlib">
115+
<value>1</value>
116+
</data>
117+
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
118+
<value>True</value>
119+
</metadata>
120+
<metadata name="$this.Language" type="System.Globalization.CultureInfo, System.Private.CoreLib, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
121+
<value>zh-Hans</value>
122+
</metadata>
123+
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
124+
<value>True</value>
125+
</metadata>
126+
</root>

0 commit comments

Comments
 (0)