/SSHelper/MainWindow.xaml.cs
C# | 280 lines | 238 code | 39 blank | 3 comment | 24 complexity | 9db37ae014b6170ad8d0a69ab45c2375 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Xml.Linq;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
-
- namespace SSHelper
- {
- /// <summary>
- /// MainWindow.xaml の相互作用ロジック
- /// </summary>
- public partial class MainWindow : Window
- {
- [StructLayout(LayoutKind.Sequential)]
- private struct RECT
- {
- public int Left;
- public int Top;
- public int Right;
- public int Bottom;
- }
-
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
-
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- private static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
-
- [DllImport("user32.dll")]
- static extern int GetSystemMetrics(SystemMetric smIndex);
- public enum SystemMetric : int
- {
- SM_CXSCREEN = 0,
- SM_CYSCREEN = 1,
- SM_CYVSCROLL = 2,
- SM_CXVSCROLL = 3,
- SM_CYCAPTION = 4,
- SM_CXBORDER = 5,
- SM_CYBORDER = 6,
- SM_CXDLGFRAME = 7,
- SM_CYDLGFRAME = 8,
- SM_CYVTHUMB = 9,
- SM_CXHTHUMB = 10,
- SM_CXICON = 11,
- SM_CYICON = 12,
- SM_CXCURSOR = 13,
- SM_CYCURSOR = 14,
- SM_CYMENU = 15,
- SM_CXFULLSCREEN = 16,
- SM_CYFULLSCREEN = 17,
- SM_CYKANJIWINDOW = 18,
- SM_MOUSEWHEELPRESENT = 75,
- SM_CYHSCROLL = 20,
- SM_CXHSCROLL = 21,
- SM_DEBUG = 22,
- SM_SWAPBUTTON = 23,
- SM_RESERVED1 = 24,
- SM_RESERVED2 = 25,
- SM_RESERVED3 = 26,
- SM_RESERVED4 = 27,
- SM_CXMIN = 28,
- SM_CYMIN = 29,
- SM_CXSIZE = 30,
- SM_CYSIZE = 31,
- SM_CXFRAME = 32,
- SM_CYFRAME = 33,
- SM_CXMINTRACK = 34,
- SM_CYMINTRACK = 35,
- SM_CXDOUBLECLK = 36,
- SM_CYDOUBLECLK = 37,
- SM_CXICONSPACING = 38,
- SM_CYICONSPACING = 39,
- SM_MENUDROPALIGNMENT = 40,
- SM_PENWINDOWS = 41,
- SM_DBCSENABLED = 42,
- SM_CMOUSEBUTTONS = 43,
- SM_CXFIXEDFRAME = SM_CXDLGFRAME,
- SM_CYFIXEDFRAME = SM_CYDLGFRAME,
- SM_CXSIZEFRAME = SM_CXFRAME,
- SM_CYSIZEFRAME = SM_CYFRAME,
- SM_SECURE = 44,
- SM_CXEDGE = 45,
- SM_CYEDGE = 46,
- SM_CXMINSPACING = 47,
- SM_CYMINSPACING = 48,
- SM_CXSMICON = 49,
- SM_CYSMICON = 50,
- SM_CYSMCAPTION = 51,
- SM_CXSMSIZE = 52,
- SM_CYSMSIZE = 53,
- SM_CXMENUSIZE = 54,
- SM_CYMENUSIZE = 55,
- SM_ARRANGE = 56,
- SM_CXMINIMIZED = 57,
- SM_CYMINIMIZED = 58,
- SM_CXMAXTRACK = 59,
- SM_CYMAXTRACK = 60,
- SM_CXMAXIMIZED = 61,
- SM_CYMAXIMIZED = 62,
- SM_NETWORK = 63,
- SM_CLEANBOOT = 67,
- SM_CXDRAG = 68,
- SM_CYDRAG = 69,
- SM_SHOWSOUNDS = 70,
- SM_CXMENUCHECK = 71,
- SM_CYMENUCHECK = 72,
- SM_SLOWMACHINE = 73,
- SM_MIDEASTENABLED = 74,
- SM_MOUSEPRESENT = 19,
- SM_XVIRTUALSCREEN = 76,
- SM_YVIRTUALSCREEN = 77,
- SM_CXVIRTUALSCREEN = 78,
- SM_CYVIRTUALSCREEN = 79,
- SM_CMONITORS = 80,
- SM_SAMEDISPLAYFORMAT = 81,
- SM_IMMENABLED = 82,
- SM_CXFOCUSBORDER = 83,
- SM_CYFOCUSBORDER = 84,
- SM_TABLETPC = 86,
- SM_MEDIACENTER = 87,
- SM_CMETRICS_OTHER = 76,
- SM_CMETRICS_2000 = 83,
- SM_CMETRICS_NT = 88,
- SM_REMOTESESSION = 0x1000,
- SM_SHUTTINGDOWN = 0x2000,
- SM_REMOTECONTROL = 0x2001,
- }
-
-
- List<string> figures = new List<string>{
- "小×",
- "大×",
- "小+",
- "大+",
- "●",
- };
-
- private string targetName = string.Empty;
- private Window targetWindow = null;
-
- public MainWindow()
- {
- InitializeComponent();
-
- LoadConfig();
-
- figures.AddRange((Directory.GetFiles(Directory.GetCurrentDirectory()).Where(x => System.IO.Path.GetExtension(x) == ".png")).Select(x => System.IO.Path.GetFileName(x)));
- comboBoxFigure.ItemsSource = figures;
-
- comboBoxFigure.SelectedIndex = 0;
- comboBoxColor.SelectedIndex = 0;
-
- }
-
-
- private void LoadConfig()
- {
- var xml = XElement.Load("Config.xml");
-
- this.targetName = xml.Element("TargetName").Value;
-
- var rgbs = xml.Descendants("RGB").Select(x => x.Value)
- .Select(x => x.Split(',').Select(y => byte.Parse(y)).ToArray())
- .Select(x => Color.FromRgb(x[0], x[1], x[2]));
-
- comboBoxColor.ItemsSource = rgbs;
- }
-
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
-
- var ps = Process.GetProcessesByName(targetName).FirstOrDefault();
- if (ps == null)
- {
- MessageBox.Show(targetName + "が見つかりません");
- }
- else
- {
- if (targetWindow != null)
- {
- targetWindow.Close();
- targetWindow = null;
- }
-
-
- var isSmall = false;
- var item = comboBoxFigure.SelectedItem as string;
- var color = (Color)comboBoxColor.SelectedItem;
- var transparency = (100.0 - sliderTransparency.Value) / 100.0;
-
- if (item == "小×" || item == "大×")
- {
- targetWindow = new CrossWindow(color, transparency);
-
- if (item.StartsWith("小")) isSmall = true;
- }
- else if (item == "小+" || item == "大+")
- {
- targetWindow = new PlusWindow(color, transparency);
-
- if (item.StartsWith("小")) isSmall = true;
- }
- else if (item == "●")
- {
- targetWindow = new DotWindow(color, transparency);
- }
- else if (File.Exists(System.IO.Path.Combine(Directory.GetCurrentDirectory(), comboBoxFigure.SelectedItem as string)))
- {
- targetWindow = new ImageWindow(System.IO.Path.Combine(Directory.GetCurrentDirectory(), comboBoxFigure.SelectedItem as string), transparency);
-
- isSmall = true;
- }
-
-
- targetWindow.Owner = this;
-
- RECT rect;
- GetClientRect(ps.MainWindowHandle, out rect);
-
- var xOffset = 0;
- var yOFfset = 0;
- if (isSmall)
- {
- var size = Math.Min(rect.Right, rect.Bottom) / 20;
- targetWindow.Width = size;
- targetWindow.Height = size;
-
- xOffset = (rect.Right - size) / 2;
- yOFfset = (rect.Bottom - size) / 2;;
- }
- else
- {
- targetWindow.Width = rect.Right;
- targetWindow.Height = rect.Bottom;
- }
-
- GetWindowRect(ps.MainWindowHandle, out rect);
-
- int cxSizeFrame = GetSystemMetrics(SystemMetric.SM_CXSIZEFRAME); // 境界線幅X方向
- int cySizeFrame = GetSystemMetrics(SystemMetric.SM_CYSIZEFRAME); // 境界線幅Y方向
- int cyCaption = GetSystemMetrics(SystemMetric.SM_CYCAPTION); // タイトルバーの高さ
-
-
- targetWindow.Left = rect.Left + cxSizeFrame + xOffset;
- targetWindow.Top = rect.Top + cyCaption + cySizeFrame + yOFfset;
-
- targetWindow.Show();
- }
- }
-
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- if (targetWindow != null)
- {
- targetWindow.Close();
- targetWindow = null;
- }
- }
-
-
- }
- }