public void GoPoint(Point newpoint) { Control cWnd; IntPtr hWnd = WindowFunctions.GetWindowAtPoint(newpoint, out cWnd); Rectangle WindowLoc = WindowFunctions.GetRectFromHwnd(hWnd); this.Location = new Point(WindowLoc.Left, WindowLoc.Top); this.Size = new Size(WindowLoc.Width, WindowLoc.Height); this.TrackedWindow = hWnd; //Console.WriteLine(this.Location.ToString() + " " + WindowFunctions.GetWindowText(hWnd)); this.Invalidate(); }
// Takes a screenshot of the SnapRegion and returns it private Image Snap() { bool VfwWasVisible = vfw.Visible; if (VfwWasVisible) { vfw.Visible = false; // Hide viewfinder if appropriate } this.Visible = false; // Hide self (nobody wants to translate Babel) try { if ((int)TrackingWindow != 0) { // Put this into a general function later Rectangle WindowLoc = WindowFunctions.GetRectFromHwnd(TrackingWindow); vfw.Location = new Point(WindowLoc.Left, WindowLoc.Top); vfw.Size = new Size(WindowLoc.Width, WindowLoc.Height); vfw.Flicker(); } Image result = GDI32.Grab(SnapRegion); if (VfwWasVisible) { vfw.Visible = true; // Reshow viewfinder if appropriate } this.Visible = true; // Show self again this.Focus(); // Return focus to the main form DebugLog.Log("Took snap"); return(result); } catch (Exception ex) { DebugLog.Log(ex.Message); return(null); } }