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 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 }
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; } }); } }