diff --git a/ShareX.HelpersLib/Native/WindowInfo.cs b/ShareX.HelpersLib/Native/WindowInfo.cs index fd69d9f9c..adf127df6 100644 --- a/ShareX.HelpersLib/Native/WindowInfo.cs +++ b/ShareX.HelpersLib/Native/WindowInfo.cs @@ -144,6 +144,14 @@ public void Activate() } } + public void BringToFront() + { + if (IsHandleCreated) + { + SetWindowPos(SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE); + } + } + public void Restore() { if (IsHandleCreated) diff --git a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureLightForm.cs b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureLightForm.cs index 5bf6a376a..04388459e 100644 --- a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureLightForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureLightForm.cs @@ -30,6 +30,7 @@ You should have received a copy of the GNU General Public License using System.Drawing.Imaging; using System.Runtime.InteropServices; using System.Threading; +using System.Threading.Tasks; using System.Windows.Forms; namespace ShareX.ScreenCaptureLib @@ -40,7 +41,7 @@ public partial class ScrollingCaptureLightForm : Form public Bitmap Result { get; private set; } private List images = new List(); - private bool isCapturing, firstCapture; + private bool isCapturing, scrollTop; private int currentScrollCount; private WindowInfo selectedWindow; private Rectangle selectedRectangle; @@ -86,7 +87,9 @@ private void StartCapture() if (!isCapturing) { isCapturing = true; - firstCapture = true; + scrollTop = true; + // TODO: Translate + btnCapture.Text = "Stop"; WindowState = FormWindowState.Minimized; Reset(); selectedWindow.Activate(); @@ -96,16 +99,20 @@ private void StartCapture() } } - private void StopCapture() + private async Task StopCapture() { if (isCapturing) { tCapture.Stop(); + // TODO: Translate + btnCapture.Text = "Capture..."; + btnCapture.Enabled = false; this.ForceActivate(); - Result = CombineImages(images); + Result = await CombineImagesAsync(images); pbOutput.Image = Result; + btnCapture.Enabled = true; isCapturing = false; } } @@ -148,13 +155,8 @@ private void SelectWindow() WindowState = FormWindowState.Minimized; Thread.Sleep(250); - SimpleWindowInfo simpleWindowInfo = RegionCaptureTasks.GetWindowInfo(new RegionCaptureOptions()); - - if (simpleWindowInfo != null) + if (RegionCaptureTasks.GetRectangleRegion(out selectedRectangle, out selectedWindow, new RegionCaptureOptions())) { - selectedWindow = new WindowInfo(simpleWindowInfo.Handle); - selectedRectangle = simpleWindowInfo.Rectangle; - StartCapture(); } else @@ -163,6 +165,11 @@ private void SelectWindow() } } + private async Task CombineImagesAsync(List images) + { + return await Task.Run(() => CombineImages(images)); + } + private Bitmap CombineImages(List images) { Bitmap result = (Bitmap)images[0].Clone(); @@ -253,11 +260,11 @@ private Bitmap CombineImages(List images) return result; } - private void btnCapture_Click(object sender, EventArgs e) + private async void btnCapture_Click(object sender, EventArgs e) { if (isCapturing) { - StopCapture(); + await StopCapture(); } else { @@ -270,11 +277,11 @@ private void btnOptions_Click(object sender, EventArgs e) } - private void tCapture_Tick(object sender, EventArgs e) + private async void tCapture_Tick(object sender, EventArgs e) { - if (firstCapture) + if (scrollTop) { - firstCapture = false; + scrollTop = false; tCapture.Interval = Options.ScrollDelay; InputHelpers.SendKeyPress(VirtualKeyCode.HOME); @@ -293,11 +300,13 @@ private void tCapture_Tick(object sender, EventArgs e) if (currentScrollCount == Options.MaximumScrollCount || (Options.AutoDetectScrollEnd && IsScrollReachedBottom(selectedWindow.Handle))) { - StopCapture(); + await StopCapture(); + } + else + { + InputHelpers.SendMouseWheel(-120 * 2); + currentScrollCount++; } - - InputHelpers.SendMouseWheel(-120 * 2); - currentScrollCount++; } } } \ No newline at end of file