public static void Initialize(Overlay o, Rectangle rect) { HookManager.KeyDown += OnKeyDown; Async.StartAsync((Action)delegate { Temp tmp = new Temp(); Bitmap img = new Bitmap(rect.Width, rect.Height); Graphics g = Graphics.FromImage(img); g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; long ticks = DateTime.Now.Ticks, next = 0, miliseconds = TimeSpan.TicksPerMillisecond * 33; while (running) { Thread.Sleep(1); ticks = DateTime.Now.Ticks; if (ticks > next) { next = ticks + miliseconds; g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; g.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy); WinAPI.CURSORINFO pci; pci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(WinAPI.CURSORINFO)); if (WinAPI.GetCursorInfo(out pci)) { if (pci.flags == WinAPI.CURSOR_SHOWING) { g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; WinAPI.DrawIcon(g.GetHdc(), pci.ptScreenPos.x - rect.Left, pci.ptScreenPos.y - rect.Top, pci.hCursor); g.ReleaseHdc(); } } tmp.AddImage(img); } } g.Dispose(); img.Dispose(); o.Invoke((Action)delegate { o.Close(); o.Dispose(); }); }); o.Visible = false; o.ShowDialog(); //Overlay needs to be choked like the dirty w***e it is for it to not crash }
public ClickCapture(Overlay overlay) { this.overlay = overlay; InitializeComponent(); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.TopLevel = true; this.TopMost = true; this.ShowInTaskbar = false; this.Location = new Point(0, 0); int height = 0, width = 0; foreach (Screen scr in Screen.AllScreens) { width += scr.Bounds.Width; if (scr.Bounds.Height > height) height = scr.Bounds.Height; } overlay.Size = this.Size = new Size(width, height); overlay.W = width; overlay.H = height; overlay.SetSize(width, height); this.Cursor = Cursors.Cross; bool dragging = false; bool active = true; this.MouseDown += (object sender, MouseEventArgs e) => { if (!active) return; dragging = true; this.L = e.X; this.T = e.Y; this.R = e.X; this.B = e.Y; overlay.L = e.X; overlay.T = e.Y; overlay.R = e.X; overlay.B = e.Y; overlay.Update(); overlay.Show(); }; this.MouseMove += (object sender, MouseEventArgs e) => { if (!active) return; if (!dragging) return; bool flag = false; foreach(Screen scr in Screen.AllScreens) if (e.X > scr.Bounds.Right - 8 && e.X < scr.Bounds.Right + 8) { this.R = scr.Bounds.Right; flag = true; break; } if(!flag) this.R = e.X; this.B = e.Y; if (this.R < this.L) { overlay.L = this.R; overlay.R = this.L; } else { overlay.L = this.L; overlay.R = this.R; } if (this.B < this.T) { overlay.T = this.B; overlay.B = this.T; } else { overlay.T = this.T; overlay.B = this.B; } overlay.Update(); }; this.MouseUp += delegate { dragging = false; active = false; this.X = (this.R < this.L ? this.R : this.L); this.Y = (this.B < this.T ? this.B : this.T); this.W = (this.R < this.L ? this.L - this.R : this.R - this.L); this.H = (this.B < this.T ? this.T - this.B : this.B - this.T); this.Close(); }; }
static void KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Control || e.KeyCode == Keys.ControlKey || e.KeyCode == Keys.LControlKey || e.KeyCode == Keys.RControlKey) ctrl = true; else if (e.KeyCode == Keys.Alt) alt = true; else if (e.KeyCode == Keys.Shift || e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.LShiftKey || e.KeyCode == Keys.RShiftKey) shift = true; else if (e.KeyValue == Settings.HotkeyImage && ctrl == Settings.HotkeyImageCtrl && alt == Settings.HotkeyImageAlt && shift == Settings.HotkeyImageShift) { e.SuppressKeyPress = true; if (incapture) { if (!tmpcap.IsDisposed) tmpcap.Invoke((Action)delegate { WinAPI.SetWindowPos(tmpcap.Handle, new IntPtr(-1), 0, 0, tmpcap.Width, tmpcap.Height, 0); }); return; } Async.StartAsync(delegate { incapture = true; Overlay overlay = new Overlay(); ClickCapture cap = new ClickCapture(overlay); tmpcap = cap; cap.ShowDialog(); cap.Dispose(); overlay.Close(); overlay.Dispose(); if (cap.W > 0 && cap.H > 0) { //MessageBox.Show(cap.X + ":" + cap.Y + ":" + cap.W + "x" + cap.H); Bitmap img = new Bitmap(cap.W, cap.H); using (Graphics g = Graphics.FromImage(img)) g.CopyFromScreen(cap.X, cap.Y, 0, 0, img.Size, CopyPixelOperation.SourceCopy); if (Settings.PostCapture == 0) STAThread.Send(delegate { Clipboard.SetImage(img); }, null); else if (Settings.PostCapture == 1) { STAThread.Send(delegate { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "PNG Image (*.png)|*.png"; if (sfd.ShowDialog() == DialogResult.OK) img.Save(sfd.FileName, System.Drawing.Imaging.ImageFormat.Png); }, null); } else if (Settings.PostCapture == 2) { Midori.Upload((Midori.UploadStreamHandler)delegate(Stream str) { img.Save(str, System.Drawing.Imaging.ImageFormat.Png); }, "image/png", "png", (Midori.UploadCallback) delegate(string s) { STAThread.Send(delegate { Clipboard.SetText(s); ico.ShowBalloonTip(3, "Info", "Link copied to clipboard", ToolTipIcon.Info); }, null); }); } img.Dispose(); } incapture = false; }); } else if (e.KeyValue == Settings.HotkeyVideo && ctrl == Settings.HotkeyImageCtrl && alt == Settings.HotkeyImageAlt && shift == Settings.HotkeyImageShift) { e.SuppressKeyPress = true; if (incapture) { if(!tmpcap.IsDisposed) tmpcap.Invoke((Action)delegate { WinAPI.SetWindowPos(tmpcap.Handle, new IntPtr(-1), 0, 0, tmpcap.Width, tmpcap.Height, 0); }); return; } Async.StartAsync(delegate { incapture = true; Overlay overlay = new Overlay(); ClickCapture cap = new ClickCapture(overlay); tmpcap = cap; cap.ShowDialog(); cap.Dispose(); try { VideoCapture.Initialize(overlay, new Rectangle(cap.X, cap.Y, cap.W, cap.H)); //We really dont need more clutter in here } catch (Exception ex) { new Error(ex.ToString()); } finally { if (!overlay.IsDisposed) { overlay.Close(); overlay.Dispose(); } incapture = false; } }); } }
static void KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Control || e.KeyCode == Keys.ControlKey || e.KeyCode == Keys.LControlKey || e.KeyCode == Keys.RControlKey) { ctrl = true; } else if (e.KeyCode == Keys.Alt) { alt = true; } else if (e.KeyCode == Keys.Shift || e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.LShiftKey || e.KeyCode == Keys.RShiftKey) { shift = true; } else if (e.KeyValue == Settings.HotkeyImage && ctrl == Settings.HotkeyImageCtrl && alt == Settings.HotkeyImageAlt && shift == Settings.HotkeyImageShift) { e.SuppressKeyPress = true; if (incapture) { if (!tmpcap.IsDisposed) { tmpcap.Invoke((Action) delegate { WinAPI.SetWindowPos(tmpcap.Handle, new IntPtr(-1), 0, 0, tmpcap.Width, tmpcap.Height, 0); }); } return; } Async.StartAsync(delegate { incapture = true; Overlay overlay = new Overlay(); ClickCapture cap = new ClickCapture(overlay); tmpcap = cap; cap.ShowDialog(); cap.Dispose(); overlay.Close(); overlay.Dispose(); if (cap.W > 0 && cap.H > 0) { //MessageBox.Show(cap.X + ":" + cap.Y + ":" + cap.W + "x" + cap.H); Bitmap img = new Bitmap(cap.W, cap.H); using (Graphics g = Graphics.FromImage(img)) g.CopyFromScreen(cap.X, cap.Y, 0, 0, img.Size, CopyPixelOperation.SourceCopy); if (Settings.PostCapture == 0) { STAThread.Send(delegate { Clipboard.SetImage(img); }, null); } else if (Settings.PostCapture == 1) { STAThread.Send(delegate { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "PNG Image (*.png)|*.png"; if (sfd.ShowDialog() == DialogResult.OK) { img.Save(sfd.FileName, System.Drawing.Imaging.ImageFormat.Png); } }, null); } else if (Settings.PostCapture == 2) { Midori.Upload((Midori.UploadStreamHandler) delegate(Stream str) { img.Save(str, System.Drawing.Imaging.ImageFormat.Png); }, "image/png", "png", (Midori.UploadCallback) delegate(string s) { STAThread.Send(delegate { Clipboard.SetText(s); ico.ShowBalloonTip(3, "Info", "Link copied to clipboard", ToolTipIcon.Info); }, null); }); } img.Dispose(); } incapture = false; }); } else if (e.KeyValue == Settings.HotkeyVideo && ctrl == Settings.HotkeyImageCtrl && alt == Settings.HotkeyImageAlt && shift == Settings.HotkeyImageShift) { e.SuppressKeyPress = true; if (incapture) { if (!tmpcap.IsDisposed) { tmpcap.Invoke((Action) delegate { WinAPI.SetWindowPos(tmpcap.Handle, new IntPtr(-1), 0, 0, tmpcap.Width, tmpcap.Height, 0); }); } return; } Async.StartAsync(delegate { incapture = true; Overlay overlay = new Overlay(); ClickCapture cap = new ClickCapture(overlay); tmpcap = cap; cap.ShowDialog(); cap.Dispose(); try { VideoCapture.Initialize(overlay, new Rectangle(cap.X, cap.Y, cap.W, cap.H)); //We really dont need more clutter in here } catch (Exception ex) { new Error(ex.ToString()); } finally { if (!overlay.IsDisposed) { overlay.Close(); overlay.Dispose(); } incapture = false; } }); } }