public static IntPtr SetWindow() { IntPtr curWin = WindowUtil.GetForegroundWindow(); IntPtr gameWin = WindowUtil.GetIdleChampsWindow(); WindowUtil.SetForegroundWindow(gameWin); return(curWin); }
public static void ReturnToPreviousWindowstate() { if (_wasMinimized) { IntPtr ptr = WindowUtil.GetIdleChampsWindow(); if (ptr == IntPtr.Zero) { return; } WindowUtil.Minimize(ptr); } if (_curWin != IntPtr.Zero) { WindowUtil.SetForegroundWindow(_curWin); } }
public static Bitmap GetSnapshot(bool saveSnap = false) { IntPtr idleChampsHandle = WindowUtil.GetIdleChampsWindow(); if (idleChampsHandle == IntPtr.Zero) { return(null); } _curWin = WindowUtil.GetForegroundWindow(); #region Ensure the IdleChamps window is fully visible, and topmost #region Restore if Minimized Rectangle bounds; if (WindowUtil.IsMinimized(idleChampsHandle)) { _wasMinimized = true; WindowUtil.Restore(idleChampsHandle); Thread.Sleep(1000);//restore animation time holder, could pull this from registry? Snapshot is wrong if it's still expanding. } else { _wasMinimized = false; } #endregion Restore if Minimized WindowUtil.SetForegroundWindow(idleChampsHandle); #region If the window has a portion off-screen, fix that (assumes putting the top corner at 10,10 will fix the problem) //edge case, if the window (whether we restored it or not) is off the edge of the screen, move it so that it isn't. //rather than testing things, just put the upper left at 10,10 //assume taskbar is 50px WindowUtil.FixOffScreen(idleChampsHandle); #endregion If the window has a portion off-screen, fix that (assumes putting the top corner at 10,10 will fix the problem) #endregion Ensure the IdleChamps window is fully visible, and topmost #region Snapshot the window into a Bitmap Obj var rect = new WindowUtil.Rect(); WindowUtil.GetWindowRect(idleChampsHandle, ref rect); bounds = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top); var result = new Bitmap(bounds.Width, bounds.Height); using (var g = Graphics.FromImage(result)) { g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size); } #endregion Snapshot the window into a Bitmap Obj #region Return desktop state to where it was #endregion Return desktop state to where it was //test writing to desktop, used to determine where the autoprogress arrow is if (saveSnap) { try { result.Save(@"C:\users\Dave\Desktop\test.png", System.Drawing.Imaging.ImageFormat.Png); } catch (Exception ex) { Console.WriteLine(ex); } } return(result);//remember to dispose result, bitmap leaks otherwise. }