Alternative way if GetScrollInfo fails

This commit is contained in:
Jaex 2015-09-25 13:32:53 +03:00
parent 44c8df80ba
commit 6381336f37
3 changed files with 115 additions and 88 deletions

View file

@ -475,14 +475,5 @@ public static bool FlashWindowEx(Form frm)
return FlashWindowEx(ref fInfo); return FlashWindowEx(ref fInfo);
} }
public static bool IsScrollReachedBottom(IntPtr handle)
{
SCROLLINFO scrollInfo = new SCROLLINFO();
scrollInfo.cbSize = (uint)Marshal.SizeOf(scrollInfo);
scrollInfo.fMask = (uint)(ScrollInfoMask.SIF_RANGE | ScrollInfoMask.SIF_PAGE | ScrollInfoMask.SIF_TRACKPOS);
NativeMethods.GetScrollInfo(handle, (int)SBOrientation.SB_VERT, ref scrollInfo);
return scrollInfo.nMax == scrollInfo.nTrackPos + scrollInfo.nPage - 1;
}
} }
} }

View file

@ -1,11 +1,18 @@
namespace ShareX.ScreenCaptureLib using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ShareX.HelpersLib;
namespace ShareX.ScreenCaptureLib
{ {
partial class ScrollingCaptureForm partial class ScrollingCaptureForm
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private IContainer components = null;
#region Windows Form Designer generated code #region Windows Form Designer generated code
@ -15,100 +22,100 @@ partial class ScrollingCaptureForm
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.components = new Container();
this.btnSelectHandle = new System.Windows.Forms.Button(); this.btnSelectHandle = new Button();
this.lblControlText = new System.Windows.Forms.Label(); this.lblControlText = new Label();
this.btnCapture = new System.Windows.Forms.Button(); this.btnCapture = new Button();
this.captureTimer = new System.Windows.Forms.Timer(this.components); this.captureTimer = new Timer(this.components);
this.nudScrollDelay = new System.Windows.Forms.NumericUpDown(); this.nudScrollDelay = new NumericUpDown();
this.nudMaximumScrollCount = new System.Windows.Forms.NumericUpDown(); this.nudMaximumScrollCount = new NumericUpDown();
this.lblScrollDelay = new System.Windows.Forms.Label(); this.lblScrollDelay = new Label();
this.lblMaximumScrollCount = new System.Windows.Forms.Label(); this.lblMaximumScrollCount = new Label();
this.tcScrollingCapture = new System.Windows.Forms.TabControl(); this.tcScrollingCapture = new TabControl();
this.tpCapture = new System.Windows.Forms.TabPage(); this.tpCapture = new TabPage();
this.tpOutput = new System.Windows.Forms.TabPage(); this.tpOutput = new TabPage();
this.pbOutput = new System.Windows.Forms.PictureBox(); this.pbOutput = new PictureBox();
this.pOutput = new System.Windows.Forms.Panel(); this.pOutput = new Panel();
((System.ComponentModel.ISupportInitialize)(this.nudScrollDelay)).BeginInit(); ((ISupportInitialize)(this.nudScrollDelay)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudMaximumScrollCount)).BeginInit(); ((ISupportInitialize)(this.nudMaximumScrollCount)).BeginInit();
this.tcScrollingCapture.SuspendLayout(); this.tcScrollingCapture.SuspendLayout();
this.tpCapture.SuspendLayout(); this.tpCapture.SuspendLayout();
this.tpOutput.SuspendLayout(); this.tpOutput.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbOutput)).BeginInit(); ((ISupportInitialize)(this.pbOutput)).BeginInit();
this.pOutput.SuspendLayout(); this.pOutput.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// btnSelectHandle // btnSelectHandle
// //
this.btnSelectHandle.Location = new System.Drawing.Point(12, 10); this.btnSelectHandle.Location = new Point(12, 10);
this.btnSelectHandle.Name = "btnSelectHandle"; this.btnSelectHandle.Name = "btnSelectHandle";
this.btnSelectHandle.Size = new System.Drawing.Size(304, 23); this.btnSelectHandle.Size = new Size(304, 23);
this.btnSelectHandle.TabIndex = 0; this.btnSelectHandle.TabIndex = 0;
this.btnSelectHandle.Text = "Select window or control to scroll"; this.btnSelectHandle.Text = "Select window or control to scroll";
this.btnSelectHandle.UseVisualStyleBackColor = true; this.btnSelectHandle.UseVisualStyleBackColor = true;
this.btnSelectHandle.Click += new System.EventHandler(this.btnSelectHandle_Click); this.btnSelectHandle.Click += new EventHandler(this.btnSelectHandle_Click);
// //
// lblControlText // lblControlText
// //
this.lblControlText.Location = new System.Drawing.Point(324, 15); this.lblControlText.Location = new Point(324, 15);
this.lblControlText.Name = "lblControlText"; this.lblControlText.Name = "lblControlText";
this.lblControlText.Size = new System.Drawing.Size(240, 19); this.lblControlText.Size = new Size(240, 19);
this.lblControlText.TabIndex = 1; this.lblControlText.TabIndex = 1;
this.lblControlText.Text = "Text"; this.lblControlText.Text = "Text";
// //
// btnCapture // btnCapture
// //
this.btnCapture.Enabled = false; this.btnCapture.Enabled = false;
this.btnCapture.Location = new System.Drawing.Point(12, 106); this.btnCapture.Location = new Point(12, 106);
this.btnCapture.Name = "btnCapture"; this.btnCapture.Name = "btnCapture";
this.btnCapture.Size = new System.Drawing.Size(152, 23); this.btnCapture.Size = new Size(152, 23);
this.btnCapture.TabIndex = 2; this.btnCapture.TabIndex = 2;
this.btnCapture.Text = "Start capture"; this.btnCapture.Text = "Start capture";
this.btnCapture.UseVisualStyleBackColor = true; this.btnCapture.UseVisualStyleBackColor = true;
this.btnCapture.Click += new System.EventHandler(this.btnCapture_Click); this.btnCapture.Click += new EventHandler(this.btnCapture_Click);
// //
// captureTimer // captureTimer
// //
this.captureTimer.Tick += new System.EventHandler(this.captureTimer_Tick); this.captureTimer.Tick += new EventHandler(this.captureTimer_Tick);
// //
// nudScrollDelay // nudScrollDelay
// //
this.nudScrollDelay.Location = new System.Drawing.Point(140, 46); this.nudScrollDelay.Location = new Point(140, 46);
this.nudScrollDelay.Maximum = new decimal(new int[] { this.nudScrollDelay.Maximum = new decimal(new int[] {
5000, 5000,
0, 0,
0, 0,
0}); 0});
this.nudScrollDelay.Name = "nudScrollDelay"; this.nudScrollDelay.Name = "nudScrollDelay";
this.nudScrollDelay.Size = new System.Drawing.Size(80, 20); this.nudScrollDelay.Size = new Size(80, 20);
this.nudScrollDelay.TabIndex = 3; this.nudScrollDelay.TabIndex = 3;
this.nudScrollDelay.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.nudScrollDelay.TextAlign = HorizontalAlignment.Center;
this.nudScrollDelay.ValueChanged += new System.EventHandler(this.nudScrollDelay_ValueChanged); this.nudScrollDelay.ValueChanged += new EventHandler(this.nudScrollDelay_ValueChanged);
// //
// nudMaximumScrollCount // nudMaximumScrollCount
// //
this.nudMaximumScrollCount.Location = new System.Drawing.Point(140, 70); this.nudMaximumScrollCount.Location = new Point(140, 70);
this.nudMaximumScrollCount.Name = "nudMaximumScrollCount"; this.nudMaximumScrollCount.Name = "nudMaximumScrollCount";
this.nudMaximumScrollCount.Size = new System.Drawing.Size(80, 20); this.nudMaximumScrollCount.Size = new Size(80, 20);
this.nudMaximumScrollCount.TabIndex = 4; this.nudMaximumScrollCount.TabIndex = 4;
this.nudMaximumScrollCount.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.nudMaximumScrollCount.TextAlign = HorizontalAlignment.Center;
this.nudMaximumScrollCount.ValueChanged += new System.EventHandler(this.nudMaximumScrollCount_ValueChanged); this.nudMaximumScrollCount.ValueChanged += new EventHandler(this.nudMaximumScrollCount_ValueChanged);
// //
// lblScrollDelay // lblScrollDelay
// //
this.lblScrollDelay.AutoSize = true; this.lblScrollDelay.AutoSize = true;
this.lblScrollDelay.Location = new System.Drawing.Point(12, 50); this.lblScrollDelay.Location = new Point(12, 50);
this.lblScrollDelay.Name = "lblScrollDelay"; this.lblScrollDelay.Name = "lblScrollDelay";
this.lblScrollDelay.Size = new System.Drawing.Size(64, 13); this.lblScrollDelay.Size = new Size(64, 13);
this.lblScrollDelay.TabIndex = 5; this.lblScrollDelay.TabIndex = 5;
this.lblScrollDelay.Text = "Scroll delay:"; this.lblScrollDelay.Text = "Scroll delay:";
// //
// lblMaximumScrollCount // lblMaximumScrollCount
// //
this.lblMaximumScrollCount.AutoSize = true; this.lblMaximumScrollCount.AutoSize = true;
this.lblMaximumScrollCount.Location = new System.Drawing.Point(12, 74); this.lblMaximumScrollCount.Location = new Point(12, 74);
this.lblMaximumScrollCount.Name = "lblMaximumScrollCount"; this.lblMaximumScrollCount.Name = "lblMaximumScrollCount";
this.lblMaximumScrollCount.Size = new System.Drawing.Size(111, 13); this.lblMaximumScrollCount.Size = new Size(111, 13);
this.lblMaximumScrollCount.TabIndex = 6; this.lblMaximumScrollCount.TabIndex = 6;
this.lblMaximumScrollCount.Text = "Maximum scroll count:"; this.lblMaximumScrollCount.Text = "Maximum scroll count:";
// //
@ -116,11 +123,11 @@ private void InitializeComponent()
// //
this.tcScrollingCapture.Controls.Add(this.tpCapture); this.tcScrollingCapture.Controls.Add(this.tpCapture);
this.tcScrollingCapture.Controls.Add(this.tpOutput); this.tcScrollingCapture.Controls.Add(this.tpOutput);
this.tcScrollingCapture.Dock = System.Windows.Forms.DockStyle.Fill; this.tcScrollingCapture.Dock = DockStyle.Fill;
this.tcScrollingCapture.Location = new System.Drawing.Point(0, 0); this.tcScrollingCapture.Location = new Point(0, 0);
this.tcScrollingCapture.Name = "tcScrollingCapture"; this.tcScrollingCapture.Name = "tcScrollingCapture";
this.tcScrollingCapture.SelectedIndex = 0; this.tcScrollingCapture.SelectedIndex = 0;
this.tcScrollingCapture.Size = new System.Drawing.Size(567, 427); this.tcScrollingCapture.Size = new Size(567, 427);
this.tcScrollingCapture.TabIndex = 7; this.tcScrollingCapture.TabIndex = 7;
// //
// tpCapture // tpCapture
@ -132,10 +139,10 @@ private void InitializeComponent()
this.tpCapture.Controls.Add(this.btnCapture); this.tpCapture.Controls.Add(this.btnCapture);
this.tpCapture.Controls.Add(this.nudMaximumScrollCount); this.tpCapture.Controls.Add(this.nudMaximumScrollCount);
this.tpCapture.Controls.Add(this.nudScrollDelay); this.tpCapture.Controls.Add(this.nudScrollDelay);
this.tpCapture.Location = new System.Drawing.Point(4, 22); this.tpCapture.Location = new Point(4, 22);
this.tpCapture.Name = "tpCapture"; this.tpCapture.Name = "tpCapture";
this.tpCapture.Padding = new System.Windows.Forms.Padding(3); this.tpCapture.Padding = new Padding(3);
this.tpCapture.Size = new System.Drawing.Size(559, 401); this.tpCapture.Size = new Size(559, 401);
this.tpCapture.TabIndex = 0; this.tpCapture.TabIndex = 0;
this.tpCapture.Text = "Capture"; this.tpCapture.Text = "Capture";
this.tpCapture.UseVisualStyleBackColor = true; this.tpCapture.UseVisualStyleBackColor = true;
@ -143,51 +150,51 @@ private void InitializeComponent()
// tpOutput // tpOutput
// //
this.tpOutput.Controls.Add(this.pOutput); this.tpOutput.Controls.Add(this.pOutput);
this.tpOutput.Location = new System.Drawing.Point(4, 22); this.tpOutput.Location = new Point(4, 22);
this.tpOutput.Name = "tpOutput"; this.tpOutput.Name = "tpOutput";
this.tpOutput.Padding = new System.Windows.Forms.Padding(3); this.tpOutput.Padding = new Padding(3);
this.tpOutput.Size = new System.Drawing.Size(559, 401); this.tpOutput.Size = new Size(559, 401);
this.tpOutput.TabIndex = 1; this.tpOutput.TabIndex = 1;
this.tpOutput.Text = "Output"; this.tpOutput.Text = "Output";
this.tpOutput.UseVisualStyleBackColor = true; this.tpOutput.UseVisualStyleBackColor = true;
// //
// pbOutput // pbOutput
// //
this.pbOutput.Location = new System.Drawing.Point(0, 0); this.pbOutput.Location = new Point(0, 0);
this.pbOutput.Name = "pbOutput"; this.pbOutput.Name = "pbOutput";
this.pbOutput.Size = new System.Drawing.Size(100, 100); this.pbOutput.Size = new Size(100, 100);
this.pbOutput.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pbOutput.SizeMode = PictureBoxSizeMode.AutoSize;
this.pbOutput.TabIndex = 0; this.pbOutput.TabIndex = 0;
this.pbOutput.TabStop = false; this.pbOutput.TabStop = false;
// //
// pOutput // pOutput
// //
this.pOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.pOutput.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | AnchorStyles.Right)));
this.pOutput.AutoScroll = true; this.pOutput.AutoScroll = true;
this.pOutput.Controls.Add(this.pbOutput); this.pOutput.Controls.Add(this.pbOutput);
this.pOutput.Location = new System.Drawing.Point(8, 8); this.pOutput.Location = new Point(8, 8);
this.pOutput.Name = "pOutput"; this.pOutput.Name = "pOutput";
this.pOutput.Size = new System.Drawing.Size(544, 384); this.pOutput.Size = new Size(544, 384);
this.pOutput.TabIndex = 1; this.pOutput.TabIndex = 1;
// //
// ScrollingCaptureForm // ScrollingCaptureForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(567, 427); this.ClientSize = new Size(567, 427);
this.Controls.Add(this.tcScrollingCapture); this.Controls.Add(this.tcScrollingCapture);
this.Name = "ScrollingCaptureForm"; this.Name = "ScrollingCaptureForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = FormStartPosition.CenterScreen;
this.Text = "ShareX - Scrolling capture"; this.Text = "ShareX - Scrolling capture";
((System.ComponentModel.ISupportInitialize)(this.nudScrollDelay)).EndInit(); ((ISupportInitialize)(this.nudScrollDelay)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudMaximumScrollCount)).EndInit(); ((ISupportInitialize)(this.nudMaximumScrollCount)).EndInit();
this.tcScrollingCapture.ResumeLayout(false); this.tcScrollingCapture.ResumeLayout(false);
this.tpCapture.ResumeLayout(false); this.tpCapture.ResumeLayout(false);
this.tpCapture.PerformLayout(); this.tpCapture.PerformLayout();
this.tpOutput.ResumeLayout(false); this.tpOutput.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pbOutput)).EndInit(); ((ISupportInitialize)(this.pbOutput)).EndInit();
this.pOutput.ResumeLayout(false); this.pOutput.ResumeLayout(false);
this.pOutput.PerformLayout(); this.pOutput.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -196,18 +203,18 @@ private void InitializeComponent()
#endregion #endregion
private System.Windows.Forms.Button btnSelectHandle; private Button btnSelectHandle;
private System.Windows.Forms.Label lblControlText; private Label lblControlText;
private System.Windows.Forms.Button btnCapture; private Button btnCapture;
private System.Windows.Forms.Timer captureTimer; private Timer captureTimer;
private System.Windows.Forms.NumericUpDown nudScrollDelay; private NumericUpDown nudScrollDelay;
private System.Windows.Forms.NumericUpDown nudMaximumScrollCount; private NumericUpDown nudMaximumScrollCount;
private System.Windows.Forms.Label lblScrollDelay; private Label lblScrollDelay;
private System.Windows.Forms.Label lblMaximumScrollCount; private Label lblMaximumScrollCount;
private System.Windows.Forms.TabControl tcScrollingCapture; private TabControl tcScrollingCapture;
private System.Windows.Forms.TabPage tpCapture; private TabPage tpCapture;
private System.Windows.Forms.TabPage tpOutput; private TabPage tpOutput;
private System.Windows.Forms.Panel pOutput; private Panel pOutput;
private System.Windows.Forms.PictureBox pbOutput; private PictureBox pbOutput;
} }
} }

View file

@ -86,7 +86,7 @@ private void btnSelectHandle_Click(object sender, EventArgs e)
if (simpleWindowInfo != null) if (simpleWindowInfo != null)
{ {
selectedWindow = new WindowInfo(simpleWindowInfo.Handle); selectedWindow = new WindowInfo(simpleWindowInfo.Handle);
lblControlText.Text = selectedWindow.ClassName ?? string.Empty; lblControlText.Text = selectedWindow.ClassName ?? String.Empty;
btnCapture.Enabled = true; btnCapture.Enabled = true;
} }
else else
@ -161,6 +161,7 @@ private void Clean()
private void captureTimer_Tick(object sender, EventArgs e) private void captureTimer_Tick(object sender, EventArgs e)
{ {
Screenshot.CaptureCursor = false;
Image image = Screenshot.CaptureRectangle(selectedWindow.Rectangle); Image image = Screenshot.CaptureRectangle(selectedWindow.Rectangle);
if (image != null) if (image != null)
@ -170,7 +171,7 @@ private void captureTimer_Tick(object sender, EventArgs e)
currentScrollCount++; currentScrollCount++;
if (currentScrollCount == Options.MaximumScrollCount || NativeMethods.IsScrollReachedBottom(selectedWindow.Handle)) if (currentScrollCount == Options.MaximumScrollCount || IsScrollReachedBottom(selectedWindow.Handle))
{ {
StopCapture(); StopCapture();
} }
@ -187,5 +188,33 @@ private void nudMaximumScrollCount_ValueChanged(object sender, EventArgs e)
{ {
Options.MaximumScrollCount = (int)nudMaximumScrollCount.Value; Options.MaximumScrollCount = (int)nudMaximumScrollCount.Value;
} }
private bool IsScrollReachedBottom(IntPtr handle)
{
SCROLLINFO scrollInfo = new SCROLLINFO();
scrollInfo.cbSize = (uint)Marshal.SizeOf(scrollInfo);
scrollInfo.fMask = (uint)(ScrollInfoMask.SIF_RANGE | ScrollInfoMask.SIF_PAGE | ScrollInfoMask.SIF_TRACKPOS);
if (NativeMethods.GetScrollInfo(handle, (int)SBOrientation.SB_VERT, ref scrollInfo))
{
return scrollInfo.nMax == scrollInfo.nTrackPos + scrollInfo.nPage - 1;
}
if (images.Count > 1)
{
bool result = ImageHelpers.IsImagesEqual((Bitmap)images[images.Count - 1], (Bitmap)images[images.Count - 2]);
if (result)
{
Image last = images[images.Count - 1];
images.Remove(last);
last.Dispose();
}
return result;
}
return false;
}
} }
} }