From da957af741647f5f9282d9299d886cfb59f93323 Mon Sep 17 00:00:00 2001
From: CreepyCrafter24 <33260128+CreepyCrafter24@users.noreply.github.com>
Date: Sat, 1 Feb 2020 15:32:03 +0100
Subject: [PATCH] Added broken Time class, maybe fix Wnd32.Title
---
W32.Test/MainForm.Designer.cs | 37 +++++++++++++++++++++++++++++++++++
W32.Test/MainForm.cs | 3 +++
W32/Native/kernel32.cs | 16 +++++++++++++++
W32/Native/user32.cs | 4 ++--
W32/Time.cs | 23 ++++++++++++++++++++++
W32/W32.csproj | 1 +
W32/Wnd32.cs | 2 +-
7 files changed, 83 insertions(+), 3 deletions(-)
create mode 100644 W32/Time.cs
diff --git a/W32.Test/MainForm.Designer.cs b/W32.Test/MainForm.Designer.cs
index 4778182..3a96f19 100644
--- a/W32.Test/MainForm.Designer.cs
+++ b/W32.Test/MainForm.Designer.cs
@@ -82,6 +82,9 @@
this.desk_get = new System.Windows.Forms.Button();
this.desk_back = new System.Windows.Forms.Panel();
this.readerUpdate = new System.Windows.Forms.Timer(this.components);
+ this.time = new System.Windows.Forms.GroupBox();
+ this.time_select = new System.Windows.Forms.DateTimePicker();
+ this.time_set = new System.Windows.Forms.Button();
this.keyboard.SuspendLayout();
((System.ComponentModel.ISupportInitialize) (this.wnd_action_pos_h_bar)).BeginInit();
((System.ComponentModel.ISupportInitialize) (this.wnd_action_pos_w_bar)).BeginInit();
@@ -93,6 +96,7 @@
this.screen.SuspendLayout();
this.reader.SuspendLayout();
this.desk.SuspendLayout();
+ this.time.SuspendLayout();
this.SuspendLayout();
//
// keyboard_log
@@ -725,11 +729,40 @@
this.readerUpdate.Interval = 50;
this.readerUpdate.Tick += new System.EventHandler(this.readerUpdate_Tick);
//
+ // time
+ //
+ this.time.Controls.Add(this.time_set);
+ this.time.Controls.Add(this.time_select);
+ this.time.Location = new System.Drawing.Point(14, 486);
+ this.time.Name = "time";
+ this.time.Size = new System.Drawing.Size(287, 102);
+ this.time.TabIndex = 12;
+ this.time.TabStop = false;
+ this.time.Text = "CC-Functions.W32.Time";
+ //
+ // time_select
+ //
+ this.time_select.Location = new System.Drawing.Point(6, 26);
+ this.time_select.Name = "time_select";
+ this.time_select.Size = new System.Drawing.Size(205, 23);
+ this.time_select.TabIndex = 0;
+ //
+ // time_set
+ //
+ this.time_set.Location = new System.Drawing.Point(217, 22);
+ this.time_set.Name = "time_set";
+ this.time_set.Size = new System.Drawing.Size(64, 27);
+ this.time_set.TabIndex = 1;
+ this.time_set.Text = "Set";
+ this.time_set.UseVisualStyleBackColor = true;
+ this.time_set.Click += new System.EventHandler(this.time_set_Click);
+ //
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(959, 595);
+ this.Controls.Add(this.time);
this.Controls.Add(this.desk);
this.Controls.Add(this.reader);
this.Controls.Add(this.screen);
@@ -757,6 +790,7 @@
this.screen.ResumeLayout(false);
this.reader.ResumeLayout(false);
this.desk.ResumeLayout(false);
+ this.time.ResumeLayout(false);
this.ResumeLayout(false);
}
@@ -814,5 +848,8 @@
private System.Windows.Forms.Panel screen_img;
private System.Windows.Forms.Button screen_get;
private System.Windows.Forms.Button screen_draw;
+ private System.Windows.Forms.GroupBox time;
+ private System.Windows.Forms.DateTimePicker time_select;
+ private System.Windows.Forms.Button time_set;
}
}
\ No newline at end of file
diff --git a/W32.Test/MainForm.cs b/W32.Test/MainForm.cs
index 9c0229d..eb75660 100644
--- a/W32.Test/MainForm.cs
+++ b/W32.Test/MainForm.cs
@@ -47,6 +47,7 @@ namespace CC_Functions.W32.Test
Wnd_action_title_get_Click(null, null);
desk_get_Click(null, null);
screen_get_Click(null, null);
+ time_select.Value = DateTime.Now;
}
private Wnd32 tmpWnd
@@ -281,5 +282,7 @@ namespace CC_Functions.W32.Test
g.DrawEllipse(eye,
new RectangleF(PointF.Subtract(makePoint(50, 50), makeSizeY(15, 15)), makeSizeY(30, 30)));
}
+
+ private void time_set_Click(object sender, EventArgs e) => Time.Set(time_select.Value);
}
}
\ No newline at end of file
diff --git a/W32/Native/kernel32.cs b/W32/Native/kernel32.cs
index 6b7bfe8..5c35fab 100644
--- a/W32/Native/kernel32.cs
+++ b/W32/Native/kernel32.cs
@@ -17,5 +17,21 @@ namespace CC_Functions.W32.Native
[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
+
+ [DllImport("kernel32.dll", SetLastError = true)]
+ public static extern bool SetSystemTime(ref SYSTEMTIME st);
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct SYSTEMTIME
+ {
+ public short wYear;
+ public short wMonth;
+ public short wDayOfWeek;
+ public short wDay;
+ public short wHour;
+ public short wMinute;
+ public short wSecond;
+ public short wMilliseconds;
+ }
}
}
\ No newline at end of file
diff --git a/W32/Native/user32.cs b/W32/Native/user32.cs
index cfc60c9..0399836 100644
--- a/W32/Native/user32.cs
+++ b/W32/Native/user32.cs
@@ -56,8 +56,8 @@ namespace CC_Functions.W32.Native
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(int xPoint, int yPoint);
- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern bool SetWindowText(IntPtr hWnd, string lpString);
+ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
+ public static extern bool SetWindowTextW(IntPtr hWnd, string lpString);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
diff --git a/W32/Time.cs b/W32/Time.cs
new file mode 100644
index 0000000..b6efb67
--- /dev/null
+++ b/W32/Time.cs
@@ -0,0 +1,23 @@
+using System;
+using CC_Functions.W32.Native;
+
+namespace CC_Functions.W32
+{
+ public static class Time
+ {
+ public static void Set(DateTime time)
+ {
+ time = time.ToUniversalTime();
+ kernel32.SYSTEMTIME st = new kernel32.SYSTEMTIME
+ {
+ wYear = (short) time.Year,
+ wMonth = (short) time.Month,
+ wDay = (short) time.Day,
+ wHour = (short) time.Hour,
+ wMinute = (short) time.Minute,
+ wSecond = (short) time.Second
+ };
+ kernel32.SetSystemTime(ref st);
+ }
+ }
+}
\ No newline at end of file
diff --git a/W32/W32.csproj b/W32/W32.csproj
index 6299ee0..c13c2da 100644
--- a/W32/W32.csproj
+++ b/W32/W32.csproj
@@ -71,6 +71,7 @@
+
diff --git a/W32/Wnd32.cs b/W32/Wnd32.cs
index ce9b05d..409d9b3 100644
--- a/W32/Wnd32.cs
+++ b/W32/Wnd32.cs
@@ -108,7 +108,7 @@ namespace CC_Functions.W32
user32.GetWindowText(HWnd, sb, sb.Capacity);
return sb.ToString();
}
- set => user32.SetWindowText(HWnd, value);
+ set => user32.SetWindowTextW(HWnd, value);
}
///