private void Form1_Load(object sender, EventArgs e) { this.c = new Checker(label1, this, processBox, selectedBox, notifyIcon1); settingsForm = new SettingsForm(c); }
public static bool IsForegroundFullScreen(Checker c) { //Get the handles for the desktop and shell now. IntPtr desktopHandle; IntPtr shellHandle; desktopHandle = GetDesktopWindow(); shellHandle = GetShellWindow(); RECT appBounds; Rectangle screenBounds; IntPtr hWnd; if (Keyboard.IsKeyDown(Key.LeftShift)) { System.Windows.Forms.Cursor.Clip = Rectangle.Empty; c.shiftInterception = true; return(false); } hWnd = GetForegroundWindow(); if (hWnd != null && !hWnd.Equals(IntPtr.Zero)) { //Check we haven't picked up the desktop or the shell if (!(hWnd.Equals(desktopHandle) || hWnd.Equals(shellHandle))) { GetWindowRect(hWnd, out appBounds); //determine if window is fullscreen screenBounds = Screen.FromHandle(hWnd).Bounds; uint procid = 0; GetWindowThreadProcessId(hWnd, out procid); var proc = Process.GetProcessById((int)procid); var procFileName = GetProcessFileName(proc); if (c.savedSelectedApps.Any(x => x.ProcessName == proc.ProcessName || x.ProcessName == procFileName)) { if ((appBounds.Bottom - appBounds.Top) + 100 >= screenBounds.Height && (appBounds.Right - appBounds.Left) + 50 >= screenBounds.Width && //If shift interception is done, then the cursor must be within the app to re-active the mouselock behavior (!c.shiftInterception || (System.Windows.Forms.Cursor.Position.X >= appBounds.Left && System.Windows.Forms.Cursor.Position.X <= appBounds.Right) && System.Windows.Forms.Cursor.Position.Y >= appBounds.Top) && System.Windows.Forms.Cursor.Position.Y <= appBounds.Bottom) { //Console.WriteLine(proc.ProcessName); var offsets = c.appOffsets.ContainsKey(proc.ProcessName) ? c.appOffsets[proc.ProcessName] : null; int x = 1; int y = 1; int w = 0; int h = 0; if (offsets != null) { x = offsets.X; y = offsets.Y; w = offsets.W; h = offsets.H; } System.Windows.Forms.Cursor.Clip = new Rectangle(appBounds.Left + x, appBounds.Top + y, appBounds.Width + w, appBounds.Height + h); return(true); } else { System.Windows.Forms.Cursor.Clip = Rectangle.Empty; return(false); } } else { System.Windows.Forms.Cursor.Clip = Rectangle.Empty; return(false); } } } else { System.Windows.Forms.Cursor.Clip = Rectangle.Empty; } return(false); }