using System; using System.Linq; using System.Windows; using System.Threading; using System.Diagnostics; using System.Windows.Input; using System.Windows.Interop; using System.Runtime.InteropServices; using CefSharp; namespace Overlay { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { [DllImport("user32.dll", SetLastError = true)] private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); [DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow(); private Boolean ShowOverlay; private Process P; public MainWindow() { InitializeComponent(); } private void Test_HotKeyPressed(HotKey hotKey) { if (ShowOverlay) { ShowOverlay = false; } else { ShowOverlay = true; } } private void Window_Initialized(object sender, EventArgs e) { Browser.BrowserSettings.ApplicationCache = CefSharp.CefState.Enabled; new HotKey(Key.Insert, KeyModifier.None, Test_HotKeyPressed); P = Process.GetProcesses().Where(x => x.MainWindowTitle.ToLower().Contains("shineonline")).FirstOrDefault(); if (true == true) { Thread NewThread = new Thread(delegate () { while (true) { if (ShowOverlay && (GetForegroundWindow() == P.MainWindowHandle || GetForegroundWindow() == Process.GetCurrentProcess().MainWindowHandle)) { RECT pRect; Size cSize = new Size(); GetWindowRect(P.MainWindowHandle, out pRect); cSize.Width = pRect.Right - pRect.Left; cSize.Height = pRect.Bottom - pRect.Top; Dispatcher.Invoke(new Action(() => { this.Width = cSize.Width; this.Height = cSize.Height; this.Top = pRect.Top; this.Left = pRect.Left; Show(); })); } else { Dispatcher.Invoke(new Action(() => { Hide(); })); } Thread.Sleep(500); } }); NewThread.Start(); } if (true == true) { Thread NewThread = new Thread(delegate () { P.WaitForExit(); Dispatcher.Invoke(new Action(() => { Cef.Shutdown(); })); Process.GetCurrentProcess().Kill(); }); NewThread.Start(); } } } [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; } }