private void tbCaptureDesktop_Click(object sender, RoutedEventArgs e) { this.Hide(); ExternalWindow?.Hide(); WindowUtilities.DoEvents(); var screen = Screen.FromHandle(WindowHandle); var img = ScreenCapture.CaptureWindow(screen.Bounds); ImageCaptured.Source = ScreenCapture.ImageToBitmapSource(img); CapturedBitmap?.Dispose(); CapturedBitmap = new Bitmap(img); StatusText.Text = $"Desktop captured Image: {CapturedBitmap.Width}x{CapturedBitmap.Height}"; ExternalWindow?.Show(); this.Topmost = true; this.Show(); WindowUtilities.DoEvents(); ScreenCaptureForm_SizeChanged(this, null); }
/// <summary> /// Detach the specified widget to an external window or re-attach it again to its previous container. /// </summary> /// <param name="widgetToDetach">Widget to detach.</param> /// <param name="windowTitle">Window title.</param> /// <param name="widgetWhereReattach">Widget where reattach.</param> /// <param name="func">Function executed detaching and attaching by the view in order to do specific work as /// hiding widgets</param> public void Detach(Widget widgetToDetach, string windowTitle, Widget widgetWhereReattach, Function func) { if (externalWindow == null) { Log.Debug("Detaching widget"); externalWindow = new ExternalWindow(); externalWindow.Title = windowTitle; int window_width = widgetToDetach.Allocation.Width; int window_height = widgetToDetach.Allocation.Height; externalWindow.SetDefaultSize(window_width, window_height); externalWindow.DeleteEvent += (o, args) => Detach(widgetToDetach, windowTitle, widgetWhereReattach, func); externalWindow.Show(); widgetToDetach.Reparent(externalWindow.Box); // Hack to reposition widget window in widget for OSX externalWindow.Resize(window_width + 10, window_height); } else { Log.Debug("Attaching widget again"); widgetToDetach.Reparent(widgetWhereReattach); externalWindow.Destroy(); externalWindow = null; } func.Invoke(); }
private void tbSave_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(SaveFolder)) { SaveFolder = Path.GetTempPath(); } SaveFileDialog sd = new SaveFileDialog { Filter = "png files (*.png)|*.png|jpg files (*.jpg)|*.jpg", FilterIndex = 1, FileName = "", CheckFileExists = false, OverwritePrompt = false, AutoUpgradeEnabled = true, CheckPathExists = true, InitialDirectory = SaveFolder, RestoreDirectory = true }; var result = sd.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return; } SavedImageFile = sd.FileName; try { CapturedBitmap?.Save(SavedImageFile); } catch (Exception ex) { Cancelled = true; StatusText.Text = "Error saving image: " + ex.Message; return; } if (!string.IsNullOrEmpty(ResultFilePath)) { File.WriteAllText(ResultFilePath, SavedImageFile); } Cancelled = false; if (AutoClose) { Close(); } ExternalWindow?.Show(); ExternalWindow?.Activate(); if (WindowState != WindowState.Maximized && WindowState != WindowState.Minimized) { ScreenCaptureConfiguration.Current.WindowWidth = this.Width; ScreenCaptureConfiguration.Current.WindowHeight = this.Width; } }
internal void StopCapture(bool cancelCapture = false) { if (!IsMouseClickCapturing) { return; } CaptureTimer.Dispose(); IsMouseClickCapturing = false; Overlay?.Close(); WindowUtilities.DoEvents(); //Point pt = GetMousePosition(); //CurWindow = new WindowInfo(ScreenCapture.WindowFromPoint(new System.Drawing.Point((int)pt.X, (int)pt.Y))); Desktop.Topmost = true; Desktop.Activate(); WindowUtilities.DoEvents(); if (LastWindow != null) { var img = ScreenCapture.CaptureWindow(CurWindow.Rect); CapturedBitmap = new Bitmap(img); //CapturedBitmap = ScreenCapture.CaptureWindowBitmap(CurWindow.Handle) as Bitmap; Desktop.Close(); if (CapturedBitmap != null) { ImageCaptured.Source = ScreenCapture.BitmapToBitmapSource(CapturedBitmap); StatusText.Text = "Image capture from Screen: " + $"{CapturedBitmap.Width}x{CapturedBitmap.Height}"; ScreenCaptureForm_SizeChanged(this, null); } else { StatusText.Text = "Image capture failed."; } } //Desktop.Topmost = false; Desktop?.Close(); if (ExternalWindow != null) { ExternalWindow.Show(); ExternalWindow.Activate(); } if (cancelCapture) { CancelCapture(); } else { Show(); Activate(); } }
private void MetroWindow_Loaded(object sender, RoutedEventArgs e) { _externalWindow.Owner = this; _externalWindow.Show(); while (!_processMemory.OpenProcess(Config.ProcessName)) { Thread.Sleep(100); } Thread.Sleep(1000); Console.WriteLine("Hack on."); _timer.Tick += (o, args) => Hack.Run(_game); _timer.Interval = TimeSpan.FromMilliseconds(10); _timer.Start(); }
private void tbSave_Click(object sender, RoutedEventArgs e) { if (CapturedBitmap == null) { return; } if (string.IsNullOrEmpty(SaveFolder)) { SaveFolder = Path.GetTempPath(); } var link = FileSaver.SaveBitmapAndLinkInEditor(CapturedBitmap, noEditorEmbedding: true); if (link == null) { StatusBar.ShowStatusError("Failed to save the active image."); return; } SavedImageFile = link; ////var sd = new SaveFileDialog ////{ //// Filter = "png files (*.png)|*.png|jpg files (*.jpg)|*.jpg", //// FilterIndex = 1, //// FileName = "", //// CheckFileExists = false, //// OverwritePrompt = false, //// AutoUpgradeEnabled = true, //// CheckPathExists = true, //// InitialDirectory = SaveFolder, //// RestoreDirectory = true ////}; ////var result = sd.ShowDialog(); ////if (result != System.Windows.Forms.DialogResult.OK) //// return; ////var ext = Path.GetExtension(sd.FileName); ////SavedImageFile = sd.FileName; ////try ////{ //// if (ext == ".jpg" || ext == "jpeg") //// mmImageUtils.SaveJpeg(CapturedBitmap, SavedImageFile, //// mmApp.Configuration.Images.JpegImageCompressionLevel); //// else //// CapturedBitmap.Save(SavedImageFile); //// if (ext == ".png" || ext == ".jpeg" || ext == ".jpg") //// mmFileUtils.OptimizeImage(sd.FileName); // async ////} ////catch (Exception ex) ////{ //// Cancelled = true; //// StatusBar.ShowStatusError("Error saving image: " + ex.Message); //// return; ////} if (!string.IsNullOrEmpty(ResultFilePath)) { File.WriteAllText(ResultFilePath, SavedImageFile); } Cancelled = false; if (AutoClose) { Close(); } ExternalWindow?.Show(); ExternalWindow?.Activate(); if (WindowState != WindowState.Maximized && WindowState != WindowState.Minimized) { ScreenCaptureConfiguration.Current.WindowWidth = this.Width; ScreenCaptureConfiguration.Current.WindowHeight = this.Width; } }