Skip to content

Commit df0b40b

Browse files
2.1.5 - RELEASE - Mouse pointer is now captured.
1 parent 5d22654 commit df0b40b

File tree

7 files changed

+316
-15
lines changed

7 files changed

+316
-15
lines changed

FormMain.Designer.cs

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FormMain.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ private void LoadApplicationSettings()
356356

357357
checkBoxAutoReset.Checked = Properties.Settings.Default.AutoReset;
358358

359+
checkBoxMouse.Checked = Properties.Settings.Default.Mouse;
360+
359361
if (toolStripMenuItemPreviewAtApplicationStartup.Checked)
360362
{
361363
toolStripButtonPreview.Checked = true;
@@ -882,6 +884,9 @@ private void RunSaveApplicationSettings(DoWorkEventArgs e)
882884
Properties.Settings.Default.AutoReset = checkBoxAutoReset.Checked;
883885
Log.Write("65 Saving application settings ... AutoReset = " + checkBoxAutoReset.Checked);
884886

887+
Properties.Settings.Default.Mouse = checkBoxMouse.Checked;
888+
Log.Write("66 Saving application settings ... Mouse = " + checkBoxMouse.Checked);
889+
885890
// Passphrase is set in its own event handler and saved appropriately so that's why you won't see a line for it here :)
886891

887892
Properties.Settings.Default.Save();
@@ -2518,8 +2523,8 @@ private void TakeScreenshot()
25182523
// Active Window
25192524
if (CaptureScreenAllowed(5))
25202525
{
2521-
ScreenCapture.TakeScreenshot(null, dateTimeScreenshotTaken, ScreenCapture.Format, "5", FileSystem.UserAppDataLocalDirectory + MacroParser.ParseTags(MacroParser.ApplicationMacro, ScreenCapture.Format, "5", dateTimeScreenshotTaken), 5, ScreenshotType.Application, (long)numericUpDownJpegQualityLevel.Value);
2522-
ScreenCapture.TakeScreenshot(null, dateTimeScreenshotTaken, ScreenCapture.Format, textBoxScreen5Name.Text, ScreenCapture.Folder + MacroParser.ParseTags(ScreenCapture.Macro, ScreenCapture.Format, textBoxScreen5Name.Text, dateTimeScreenshotTaken), 5, ScreenshotType.User, (long)numericUpDownJpegQualityLevel.Value);
2526+
ScreenCapture.TakeScreenshot(null, dateTimeScreenshotTaken, ScreenCapture.Format, "5", FileSystem.UserAppDataLocalDirectory + MacroParser.ParseTags(MacroParser.ApplicationMacro, ScreenCapture.Format, "5", dateTimeScreenshotTaken), 5, ScreenshotType.Application, (long)numericUpDownJpegQualityLevel.Value, checkBoxMouse.Checked);
2527+
ScreenCapture.TakeScreenshot(null, dateTimeScreenshotTaken, ScreenCapture.Format, textBoxScreen5Name.Text, ScreenCapture.Folder + MacroParser.ParseTags(ScreenCapture.Macro, ScreenCapture.Format, textBoxScreen5Name.Text, dateTimeScreenshotTaken), 5, ScreenshotType.User, (long)numericUpDownJpegQualityLevel.Value, checkBoxMouse.Checked);
25232528
}
25242529

25252530
// All screens.
@@ -2553,8 +2558,8 @@ private void TakeScreenshot()
25532558

25542559
if (!string.IsNullOrEmpty(screenName))
25552560
{
2556-
ScreenCapture.TakeScreenshot(screen, dateTimeScreenshotTaken, ScreenCapture.Format, count.ToString(), FileSystem.UserAppDataLocalDirectory + MacroParser.ParseTags(MacroParser.ApplicationMacro, ScreenCapture.Format, count.ToString(), dateTimeScreenshotTaken), count, ScreenshotType.Application, (long)numericUpDownJpegQualityLevel.Value);
2557-
ScreenCapture.TakeScreenshot(screen, dateTimeScreenshotTaken, ScreenCapture.Format, screenName, ScreenCapture.Folder + MacroParser.ParseTags(ScreenCapture.Macro, ScreenCapture.Format, screenName, dateTimeScreenshotTaken), count, ScreenshotType.User, (long)numericUpDownJpegQualityLevel.Value);
2561+
ScreenCapture.TakeScreenshot(screen, dateTimeScreenshotTaken, ScreenCapture.Format, count.ToString(), FileSystem.UserAppDataLocalDirectory + MacroParser.ParseTags(MacroParser.ApplicationMacro, ScreenCapture.Format, count.ToString(), dateTimeScreenshotTaken), count, ScreenshotType.Application, (long)numericUpDownJpegQualityLevel.Value, checkBoxMouse.Checked);
2562+
ScreenCapture.TakeScreenshot(screen, dateTimeScreenshotTaken, ScreenCapture.Format, screenName, ScreenCapture.Folder + MacroParser.ParseTags(ScreenCapture.Macro, ScreenCapture.Format, screenName, dateTimeScreenshotTaken), count, ScreenshotType.User, (long)numericUpDownJpegQualityLevel.Value, checkBoxMouse.Checked);
25582563
}
25592564
}
25602565
}
@@ -2712,7 +2717,7 @@ private void DisplayImages(bool preview)
27122717

27132718
if (preview && CaptureScreenAllowed(count))
27142719
{
2715-
Bitmap bitmap = ScreenCapture.GetScreenBitmap(screen, (int)numericUpDownImageResolutionRatio.Value, ScreenCapture.Format);
2720+
Bitmap bitmap = ScreenCapture.GetScreenBitmap(screen, (int)numericUpDownImageResolutionRatio.Value, ScreenCapture.Format, checkBoxMouse.Checked);
27162721

27172722
if (bitmap != null)
27182723
{
@@ -3312,6 +3317,8 @@ private void Click_buttonRestoreDefaults(object sender, EventArgs e)
33123317

33133318
checkBoxAutoReset.Checked = true;
33143319

3320+
checkBoxMouse.Checked = true;
3321+
33153322
ScheduleClear();
33163323

33173324
Log.Write("Default settings restored.");

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.1.4")]
36-
[assembly: AssemblyFileVersion("2.1.4")]
35+
[assembly: AssemblyVersion("2.1.5")]
36+
[assembly: AssemblyFileVersion("2.1.5")]
3737
[assembly: NeutralResourcesLanguageAttribute("en-CA")]

Properties/Settings.Designer.cs

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Properties/Settings.settings

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="autoscreen.Properties" GeneratedClassName="Settings">
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="AutoScreenCapture.Properties" GeneratedClassName="Settings">
33
<Profiles />
44
<Settings>
55
<Setting Name="Interval" Type="System.Int32" Scope="User">
66
<Value Profile="(Default)">60000</Value>
77
</Setting>
88
<Setting Name="ApplicationVersion" Type="System.String" Scope="Application">
9-
<Value Profile="(Default)">2.1.4</Value>
9+
<Value Profile="(Default)">2.1.5</Value>
1010
</Setting>
1111
<Setting Name="ImageFormatFilter" Type="System.String" Scope="User">
1212
<Value Profile="(Default)">*.*</Value>
@@ -54,7 +54,7 @@
5454
<Value Profile="(Default)">True</Value>
5555
</Setting>
5656
<Setting Name="CaptureStopAtCheck" Type="System.Boolean" Scope="User">
57-
<Value Profile="(Default)">False</Value>
57+
<Value Profile="(Default)">True</Value>
5858
</Setting>
5959
<Setting Name="CaptureStartAtValue" Type="System.DateTime" Scope="User">
6060
<Value Profile="(Default)">11/20/2013 08:00:00</Value>
@@ -218,5 +218,8 @@
218218
<Setting Name="StartWhenWindowsStartsCheck" Type="System.Boolean" Scope="User">
219219
<Value Profile="(Default)">False</Value>
220220
</Setting>
221+
<Setting Name="Mouse" Type="System.Boolean" Scope="User">
222+
<Value Profile="(Default)">True</Value>
223+
</Setting>
221224
</Settings>
222225
</SettingsFile>

ScreenCapture.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ namespace AutoScreenCapture
1818

1919
public static class ScreenCapture
2020
{
21+
[StructLayout(LayoutKind.Sequential)]
22+
private struct CURSORINFO
23+
{
24+
public Int32 cbSize;
25+
public Int32 flags;
26+
public IntPtr hCursor;
27+
public POINTAPI ptScreenPos;
28+
}
29+
30+
[StructLayout(LayoutKind.Sequential)]
31+
private struct POINTAPI
32+
{
33+
public int x;
34+
public int y;
35+
}
36+
2137
[DllImport("user32.dll")]
2238
private static extern IntPtr GetForegroundWindow();
2339

@@ -27,6 +43,15 @@ public static class ScreenCapture
2743
[DllImport("user32.dll")]
2844
private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
2945

46+
[DllImport("user32.dll")]
47+
private static extern bool GetCursorInfo(out CURSORINFO pci);
48+
49+
[DllImport("user32.dll", SetLastError = true)]
50+
static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyHeight, int istepIfAniCur, IntPtr hbrFlickerFreeDraw, int diFlags);
51+
52+
private const Int32 CURSOR_SHOWING = 0x0001;
53+
private const Int32 DI_NORMAL = 0x0003;
54+
3055
public const int SCREEN_MAX = 4;
3156
public const int CAPTURE_LIMIT_MIN = 1;
3257
public const int CAPTURE_LIMIT_MAX = 9999;
@@ -54,7 +79,7 @@ public static class ScreenCapture
5479
public static bool RunningFromCommandLine { get; set; }
5580
public static bool LockScreenCaptureSession { get; set; }
5681

57-
public static Bitmap GetScreenBitmap(Screen screen, int ratio, string format)
82+
public static Bitmap GetScreenBitmap(Screen screen, int ratio, string format, bool mouse)
5883
{
5984
try
6085
{
@@ -75,6 +100,22 @@ public static Bitmap GetScreenBitmap(Screen screen, int ratio, string format)
75100

76101
graphicsSource.CopyFromScreen(X, Y, 0, 0, blockRegionSize, CopyPixelOperation.SourceCopy);
77102

103+
if (mouse)
104+
{
105+
CURSORINFO pci;
106+
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
107+
108+
if (GetCursorInfo(out pci))
109+
{
110+
if (pci.flags == CURSOR_SHOWING)
111+
{
112+
var hdc = graphicsSource.GetHdc();
113+
DrawIconEx(hdc, pci.ptScreenPos.x - X, pci.ptScreenPos.y - Y, pci.hCursor, 0, 0, 0, IntPtr.Zero, DI_NORMAL);
114+
graphicsSource.ReleaseHdc();
115+
}
116+
}
117+
}
118+
78119
Bitmap bitmapDestination = new Bitmap(destinationWidth, destinationHeight);
79120

80121
Graphics graphicsDestination = Graphics.FromImage(bitmapDestination);
@@ -132,13 +173,13 @@ public static string GetActiveWindowTitle()
132173
return null;
133174
}
134175

135-
public static void TakeScreenshot(Screen screen, DateTime dateTimeScreenshotTaken, string format, string screenName, string path, int screenNumber, ScreenshotType screenshotType, long jpegQualityLevel)
176+
public static void TakeScreenshot(Screen screen, DateTime dateTimeScreenshotTaken, string format, string screenName, string path, int screenNumber, ScreenshotType screenshotType, long jpegQualityLevel, bool mouse)
136177
{
137178
try
138179
{
139180
if (!string.IsNullOrEmpty(path))
140181
{
141-
Bitmap bitmap = screenNumber == 5 ? GetActiveWindowBitmap() : GetScreenBitmap(screen, Ratio, format);
182+
Bitmap bitmap = screenNumber == 5 ? GetActiveWindowBitmap() : GetScreenBitmap(screen, Ratio, format, mouse);
142183

143184
if (bitmap != null)
144185
{

0 commit comments

Comments
 (0)