This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
CC-Functions/W32.Test/MainForm.cs

288 lines
11 KiB
C#
Raw Normal View History

using System;
2019-09-07 10:12:24 +02:00
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using CC_Functions.Misc;
2020-01-15 20:41:52 +01:00
using CC_Functions.W32.DCDrawer;
2019-12-22 16:58:16 +01:00
using CC_Functions.W32.Hooks;
2019-09-07 10:12:24 +02:00
using static CC_Functions.W32.Power;
namespace CC_Functions.W32.Test
{
2020-01-15 20:41:52 +01:00
public partial class MainForm : Form
2019-09-07 10:12:24 +02:00
{
2020-01-15 20:41:52 +01:00
private static Wnd32 tmpWnd32_obj;
private static MainForm mainF;
2019-12-22 16:58:16 +01:00
private static Form frm;
private static Label lab;
private readonly KeyboardHook kHook;
private readonly MouseHook mHook;
2020-01-16 19:50:31 +01:00
private readonly Label[] readerLabels;
2020-01-15 20:41:52 +01:00
public MainForm()
2019-09-07 10:12:24 +02:00
{
InitializeComponent();
mainF = this;
2020-01-16 19:50:31 +01:00
tmpWnd32_obj = Wnd32.FromForm(this);
2019-09-07 10:12:24 +02:00
#if DEBUG
2020-01-15 20:41:52 +01:00
tmpWnd32_obj.MakeOverlay();
2019-09-07 10:12:24 +02:00
#endif
set_up_box(power_mode_box, typeof(ShutdownMode));
set_up_box(power_reason_box, typeof(ShutdownReason));
set_up_box(power_mod_box, typeof(ShutdownMod));
mHook = new MouseHook();
kHook = new KeyboardHook();
wnd_action_pos_x_bar.Maximum = Screen.PrimaryScreen.Bounds.Width;
wnd_action_pos_y_bar.Maximum = Screen.PrimaryScreen.Bounds.Height;
wnd_action_pos_w_bar.Maximum = Screen.PrimaryScreen.Bounds.Width;
wnd_action_pos_h_bar.Maximum = Screen.PrimaryScreen.Bounds.Height;
2019-09-11 11:22:16 +02:00
wnd_action_style.DataSource = Enum.GetValues(typeof(FormWindowState));
2020-01-16 19:50:31 +01:00
wnd_action_style.SelectedItem = tmpWnd32_obj.State;
2020-01-15 20:41:52 +01:00
readerLabels = Enum.GetValues(typeof(Keys)).OfType<Keys>().OrderBy(s => s.ToString()).Select(s =>
{
2020-01-16 19:50:31 +01:00
Label lab = new Label {Tag = s};
2020-01-15 20:41:52 +01:00
readerFlow.Controls.Add(lab);
return lab;
}).ToArray();
Wnd_action_title_get_Click(null, null);
desk_get_Click(null, null);
screen_get_Click(null, null);
time_select.Value = DateTime.Now;
2019-09-07 10:12:24 +02:00
}
2020-01-16 19:50:31 +01:00
private Wnd32 tmpWnd
{
get => tmpWnd32_obj;
set
{
tmpWnd32_obj = value;
Wnd_action_title_get_Click(null, null);
}
}
2019-09-07 10:12:24 +02:00
public void set_up_box(ComboBox box, Type enumT)
{
box.DataSource = Enum.GetNames(enumT);
2019-12-22 16:58:16 +01:00
Array tmp = Enum.GetValues(enumT);
2019-09-07 10:12:24 +02:00
box.Tag = new object[tmp.Length];
2019-12-22 16:58:16 +01:00
int i = 0;
foreach (object o in tmp)
2019-09-07 10:12:24 +02:00
{
((object[]) box.Tag)[i] = o;
2019-09-07 10:12:24 +02:00
i++;
}
}
2019-12-22 16:58:16 +01:00
public object get_box_value(ComboBox box) => ((object[]) box.Tag)[box.SelectedIndex];
2019-09-07 10:12:24 +02:00
2020-01-16 19:50:31 +01:00
private void Power_execute_Click(object sender, EventArgs e) => RaiseEvent(
(ShutdownMode) get_box_value(power_mode_box), (ShutdownReason) get_box_value(power_reason_box),
(ShutdownMod) get_box_value(power_mod_box));
2019-09-07 10:12:24 +02:00
2020-01-16 19:50:31 +01:00
private void Wnd_select_self_Click(object sender, EventArgs e) => tmpWnd = Wnd32.FromForm(this);
2019-09-07 10:12:24 +02:00
2020-01-16 19:50:31 +01:00
private void wnd_select_list_Click(object sender, EventArgs e) =>
tmpWnd = SelectBox.Show(Wnd32.Visible, "Please select a window") ?? tmpWnd;
2020-01-16 19:50:31 +01:00
private void Wnd_select_title_button_Click(object sender, EventArgs e) =>
tmpWnd = Wnd32.FromMetadata(null, wnd_select_title_box.Text);
2019-09-07 10:12:24 +02:00
2020-01-16 19:50:31 +01:00
private void Wnd_selet_class_button_Click(object sender, EventArgs e) =>
tmpWnd = Wnd32.FromMetadata(wnd_select_class_box.Text);
2019-09-07 10:12:24 +02:00
2020-01-16 19:50:31 +01:00
private void Wnd_action_title_set_Click(object sender, EventArgs e) => tmpWnd.Title = wnd_select_title_box.Text;
2019-09-07 10:12:24 +02:00
private void Wnd_action_title_get_Click(object sender, EventArgs e)
{
2020-01-16 19:50:31 +01:00
if (!tmpWnd.StillExists)
tmpWnd = Wnd32.FromForm(this);
wnd_select_title_box.Text = tmpWnd.Title;
wnd_action_enabled.Checked = tmpWnd.Enabled;
wnd_select_selected.Text = "Selected: " + tmpWnd.HWnd;
wnd_action_style.SelectedIndex = (int) tmpWnd.State;
wnd_select_class_box.Text = tmpWnd.ClassName;
wnd_action_visible.Checked = tmpWnd.Shown;
try
{
2020-01-16 19:50:31 +01:00
wnd_action_icon.BackgroundImage = tmpWnd.Icon.ToBitmap();
}
catch
{
wnd_action_icon.BackgroundImage = null;
}
try
{
2020-01-16 19:50:31 +01:00
wnd_action_pos_x_bar.Value = tmpWnd.Position.X;
}
catch
{
}
try
{
2020-01-16 19:50:31 +01:00
wnd_action_pos_y_bar.Value = tmpWnd.Position.Y;
}
catch
{
}
try
{
2020-01-16 19:50:31 +01:00
wnd_action_pos_w_bar.Value = tmpWnd.Position.Width;
}
catch
{
}
try
{
2020-01-16 19:50:31 +01:00
wnd_action_pos_h_bar.Value = tmpWnd.Position.Height;
}
catch
{
}
2019-09-07 10:12:24 +02:00
}
2019-12-22 16:58:16 +01:00
private void Wnd_action_enabled_CheckedChanged(object sender, EventArgs e) =>
2020-01-16 19:50:31 +01:00
tmpWnd.Enabled = wnd_action_enabled.Checked;
2019-09-11 11:22:16 +02:00
2019-12-22 16:58:16 +01:00
private void Wnd_action_visible_CheckedChanged(object sender, EventArgs e) =>
2020-01-16 19:50:31 +01:00
tmpWnd.Shown = wnd_action_visible.Checked;
2019-09-07 10:12:24 +02:00
2020-01-16 19:50:31 +01:00
private void Wnd_action_front_Click(object sender, EventArgs e) => tmpWnd.IsForeground = true;
2019-09-07 10:12:24 +02:00
2019-12-22 16:58:16 +01:00
private void Wnd_action_destroy_Click(object sender, EventArgs e) => tmpWnd.Destroy();
2019-09-07 10:12:24 +02:00
private void Wnd_select_mouse_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
2020-01-16 19:50:31 +01:00
tmpWnd = Wnd32.FromForm(this);
tmpWnd.Enabled = false;
2019-09-07 10:12:24 +02:00
frm = new Form();
frm.BackColor = Color.White;
frm.Opacity = 0.4f;
frm.FormBorderStyle = FormBorderStyle.None;
frm.WindowState = FormWindowState.Maximized;
frm.Click += Frm_Click;
frm.MouseMove += Frm_MouseMove;
lab = new Label();
frm.Controls.Add(lab);
frm.Show();
2020-01-16 19:50:31 +01:00
Wnd32.FromForm(frm).Overlay = true;
2019-09-07 10:12:24 +02:00
}
private void Frm_Click(object sender, EventArgs e)
{
frm.Hide();
frm.WindowState = FormWindowState.Minimized;
2020-01-16 19:50:31 +01:00
Wnd32 tmp = Wnd32.FromPoint(MousePosition);
tmpWnd.Enabled = true;
tmpWnd.IsForeground = true;
2019-09-07 10:12:24 +02:00
tmpWnd = tmp;
mainF.WindowState = FormWindowState.Normal;
frm.Close();
}
private void Frm_MouseMove(object sender, MouseEventArgs e)
{
2020-01-16 19:50:31 +01:00
lab.Text = Wnd32.FromPoint(MousePosition).ToString();
2019-09-07 10:12:24 +02:00
lab.Location = new Point(Cursor.Position.X + 5, Cursor.Position.Y + 5);
}
private void Mouse_enabled_CheckedChanged(object sender, EventArgs e)
{
if (mouse_enabled.Checked)
mHook.OnMouse += MHook_OnMouse;
else
mHook.OnMouse -= MHook_OnMouse;
}
2019-12-22 16:58:16 +01:00
private void MHook_OnMouse(MouseHookEventArgs args) =>
mouse_log.Text = args.Message + " -|- " + args.Point + "\r\n" + mouse_log.Text;
2019-09-07 10:12:24 +02:00
2020-01-16 19:50:31 +01:00
private void Mouse_log_TextChanged(object sender, EventArgs e) =>
mouse_log.Lines = mouse_log.Lines.Take(9).ToArray();
2019-09-07 10:12:24 +02:00
private void Keyboard_enabled_CheckedChanged(object sender, EventArgs e)
{
if (keyboard_enabled.Checked)
kHook.OnKeyPress += KHook_OnKeyPress;
else
kHook.OnKeyPress -= KHook_OnKeyPress;
}
2019-12-22 16:58:16 +01:00
private void KHook_OnKeyPress(KeyboardHookEventArgs args) =>
keyboard_log.Text = args.Key + "\r\n" + keyboard_log.Text;
2019-09-07 10:12:24 +02:00
2020-01-16 19:50:31 +01:00
private void Keyboard_log_TextChanged(object sender, EventArgs e) =>
keyboard_log.Lines = keyboard_log.Lines.Take(8).ToArray();
2019-09-07 10:12:24 +02:00
2019-12-22 16:58:16 +01:00
private void Wnd_action_pos_Click(object sender, EventArgs e) =>
2020-01-16 19:50:31 +01:00
tmpWnd.Position = new Rectangle(wnd_action_pos_x_bar.Value, wnd_action_pos_y_bar.Value,
wnd_action_pos_w_bar.Value, wnd_action_pos_h_bar.Value);
2019-09-07 10:12:24 +02:00
2020-01-15 20:41:52 +01:00
private void Wnd_action_style_SelectedIndexChanged(object sender, EventArgs e)
2019-09-07 10:12:24 +02:00
{
2020-01-15 20:41:52 +01:00
Enum.TryParse(wnd_action_style.SelectedValue.ToString(), out FormWindowState status);
2020-01-16 19:50:31 +01:00
tmpWnd.State = status;
2019-09-07 10:12:24 +02:00
}
2020-01-15 20:41:52 +01:00
private void wnd_action_overlay_CheckedChanged(object sender, EventArgs e) =>
2020-01-16 19:50:31 +01:00
tmpWnd.Overlay = wnd_action_overlay.Checked;
2020-01-15 20:41:52 +01:00
private void readerUpdate_Tick(object sender, EventArgs e)
2019-09-07 10:12:24 +02:00
{
2020-01-15 20:41:52 +01:00
for (int i = 0; i < readerLabels.Length; i++)
{
Label s = readerLabels[i];
2020-01-16 19:50:31 +01:00
Keys key = (Keys) s.Tag;
2020-01-15 20:41:52 +01:00
s.Text = $"{key.ToString()}: {key.IsDown()}";
}
2019-09-07 10:12:24 +02:00
}
2020-01-15 20:41:52 +01:00
private void desk_get_Click(object sender, EventArgs e) => desk_back.BackgroundImage = DeskMan.Wallpaper;
private void desk_draw_Click(object sender, EventArgs e)
2019-09-07 10:12:24 +02:00
{
2020-01-15 20:41:52 +01:00
using IDCDrawer drawer = DeskMan.CreateGraphics();
Graphics g = drawer.Graphics;
Pen eye = new Pen(new SolidBrush(Color.Red), 2);
2020-01-16 19:50:31 +01:00
g.DrawCurve(eye, new[] {makePoint(20, 50), makePoint(50, 65), makePoint(80, 50)});
g.DrawCurve(eye, new[] {makePoint(20, 50), makePoint(50, 35), makePoint(80, 50)});
g.DrawEllipse(eye,
new RectangleF(PointF.Subtract(makePoint(50, 50), makeSizeY(15, 15)), makeSizeY(30, 30)));
2019-09-07 10:12:24 +02:00
}
2020-01-16 19:50:31 +01:00
public static PointF makePoint(float xPercent, float yPercent) => new PointF(
(Screen.PrimaryScreen.Bounds.Width * xPercent) / 100,
(Screen.PrimaryScreen.Bounds.Height * yPercent) / 100);
2019-09-11 11:22:16 +02:00
2020-01-16 19:50:31 +01:00
public static SizeF makeSizeY(float xPercent, float yPercent) => new SizeF(
(Screen.PrimaryScreen.Bounds.Height * xPercent) / 100,
(Screen.PrimaryScreen.Bounds.Height * yPercent) / 100);
2020-01-15 20:41:52 +01:00
private void desk_set_Click(object sender, EventArgs e)
2019-09-11 11:22:16 +02:00
{
2020-01-15 20:41:52 +01:00
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Images (*.jpg, *.jpeg, *.jpe, *.jfif, *.png)|*.jpg;*.jpeg;*.jpe;*.jfif;*.png";
2020-01-16 19:50:31 +01:00
if (dlg.ShowDialog() == DialogResult.OK) DeskMan.Wallpaper = Image.FromFile(dlg.FileName);
2019-09-11 11:22:16 +02:00
}
2019-11-29 21:27:24 +01:00
2020-01-16 19:50:31 +01:00
private void screen_get_Click(object sender, EventArgs e) =>
screen_img.BackgroundImage = ScreenMan.CaptureScreen();
2020-01-15 20:41:52 +01:00
private void screen_draw_Click(object sender, EventArgs e)
{
using IDCDrawer drawer = ScreenMan.GetDrawer(false);
Graphics g = drawer.Graphics;
Pen eye = new Pen(new SolidBrush(Color.Red), 2);
2020-01-16 19:50:31 +01:00
g.DrawCurve(eye, new[] {makePoint(20, 50), makePoint(50, 65), makePoint(80, 50)});
g.DrawCurve(eye, new[] {makePoint(20, 50), makePoint(50, 35), makePoint(80, 50)});
g.DrawEllipse(eye,
new RectangleF(PointF.Subtract(makePoint(50, 50), makeSizeY(15, 15)), makeSizeY(30, 30)));
2020-01-15 20:41:52 +01:00
}
private void time_set_Click(object sender, EventArgs e) => Time.Set(time_select.Value);
2019-09-07 10:12:24 +02:00
}
2019-11-29 21:27:24 +01:00
}