Skip to content

Commit d3c3cb8

Browse files
committed
Added an opportunity to capture the window cursor.
1 parent 2c71cd0 commit d3c3cb8

File tree

9 files changed

+146
-26
lines changed

9 files changed

+146
-26
lines changed

WindowTextExtractor/Forms/MainForm.Designer.cs

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

WindowTextExtractor/Forms/MainForm.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public partial class MainForm : Form, IMessageFilter
4242
private bool _refreshImage;
4343
private bool _imageTab;
4444
private bool _isRecording;
45+
private bool _captureCursor;
4546
private DateTime? _startRecordingTime;
4647
private VideoFileWriter _videoWriter;
4748
private Bitmap _image;
@@ -70,6 +71,7 @@ public MainForm()
7071
_videoFileName = Path.Combine(AssemblyUtils.AssemblyDirectory, DEFAULT_VIDEO_FILE_NAME);
7172
_windowHandle = IntPtr.Zero;
7273
_refreshImage = true;
74+
_captureCursor = true;
7375
_imageTab = false;
7476
_isRecording = false;
7577
_startRecordingTime = null;
@@ -78,6 +80,7 @@ public MainForm()
7880
numericFps.Value = DEFAULT_FPS;
7981
numericScale.Value = DEFAULT_SCALE;
8082
cmbRefresh.SelectedIndex = 0;
83+
cmbCaptureCursor.SelectedIndex = 0;
8184
_image = null;
8285
_videoWriter = new VideoFileWriter();
8386
}
@@ -340,6 +343,7 @@ private void btnRecord_Click(object sender, EventArgs e)
340343
btnTarget.Enabled = !isRecording;
341344
btnShowHide.Enabled = !isRecording;
342345
cmbRefresh.Enabled = !isRecording;
346+
cmbCaptureCursor.Enabled = !isRecording;
343347
btnBrowseFile.Enabled = !isRecording;
344348
numericFps.Enabled = !isRecording;
345349
numericScale.Enabled = !isRecording;
@@ -390,6 +394,14 @@ private void cmbRefresh_SelectedIndexChanged(object sender, EventArgs e)
390394
}
391395
}
392396

397+
private void cmbCaptureCursor_SelectedIndexChanged(object sender, EventArgs e)
398+
{
399+
lock (_lockObject)
400+
{
401+
_captureCursor = ((ComboBox)sender).SelectedIndex == 0;
402+
}
403+
}
404+
393405
private void tabContent_SelectedIndexChanged(object sender, EventArgs e)
394406
{
395407
lock (_lockObject)
@@ -468,19 +480,21 @@ public bool PreFilterMessage(ref Message m)
468480
txtContent.Text = text == null ? "" : text.TrimEnd().TrimEnd(Environment.NewLine);
469481
txtContent.ScrollTextToEnd();
470482
var scale = 1m;
483+
var captureCursor = false;
471484
lock (_lockObject)
472485
{
473486
_windowHandle = windowHandle;
474487
scale = _scale;
488+
captureCursor = _captureCursor;
475489
}
476490
if (scale == 1m)
477491
{
478-
var newImage = WindowUtils.CaptureWindow(windowHandle);
492+
var newImage = WindowUtils.CaptureWindow(windowHandle, captureCursor);
479493
FillImage(newImage);
480494
}
481495
else
482496
{
483-
using (var image = WindowUtils.CaptureWindow(windowHandle))
497+
using (var image = WindowUtils.CaptureWindow(windowHandle, captureCursor))
484498
{
485499
var newImage = ImageUtils.ResizeImage(image, (int)(image.Width * scale), (int)(image.Height * scale));
486500
FillImage(newImage);
@@ -525,13 +539,16 @@ private void CaptureWindowCallback()
525539
var windowHandle = IntPtr.Zero;
526540
var imageTab = false;
527541
var isRecording = false;
542+
var captureCursor = false;
543+
528544

529545
lock (_lockObject)
530546
{
531547
scale = _scale;
532548
windowHandle = _windowHandle;
533549
imageTab = _imageTab;
534550
isRecording = _isRecording;
551+
captureCursor = _captureCursor;
535552
}
536553

537554
var newImage = (Bitmap)null;
@@ -542,11 +559,11 @@ private void CaptureWindowCallback()
542559
{
543560
if (scale == 1m)
544561
{
545-
newImage = WindowUtils.CaptureWindow(windowHandle);
562+
newImage = WindowUtils.CaptureWindow(windowHandle, captureCursor);
546563
}
547564
else
548565
{
549-
using (var sourceImage = WindowUtils.CaptureWindow(windowHandle))
566+
using (var sourceImage = WindowUtils.CaptureWindow(windowHandle, captureCursor))
550567
{
551568
newImage = ImageUtils.ResizeImage(sourceImage, (int)(sourceImage.Width * scale), (int)(sourceImage.Height * scale));
552569
}
@@ -652,6 +669,8 @@ private void EnableImageTabControls()
652669
btnRecord.Visible = _imageTab && btnShowHide.Visible;
653670
lblRefresh.Visible = _imageTab && btnShowHide.Visible;
654671
cmbRefresh.Visible = _imageTab && btnShowHide.Visible;
672+
lblCaptureCursor.Visible = _imageTab && btnShowHide.Visible;
673+
cmbCaptureCursor.Visible = _imageTab && btnShowHide.Visible;
655674
lblFps.Visible = _imageTab && btnShowHide.Visible;
656675
numericFps.Visible = _imageTab && btnShowHide.Visible;
657676
lblScale.Visible = _imageTab && btnShowHide.Visible;

WindowTextExtractor/Forms/MainForm.resx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,6 @@
156156
<metadata name="clmnValue.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
157157
<value>True</value>
158158
</metadata>
159-
<metadata name="clmnName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
160-
<value>True</value>
161-
</metadata>
162-
<metadata name="clmnValue.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
163-
<value>True</value>
164-
</metadata>
165159
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
166160
<value>27</value>
167161
</metadata>

WindowTextExtractor/Native/Constants.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ static class Constants
3030
public const int DWMWA_EXTENDED_FRAME_BOUNDS = 9;
3131

3232
public const int EVENT_TYPE = 1;
33+
34+
public const int CURSOR_SHOWING = 0x00000001;
35+
36+
public const int DI_COMPAT = 0x0004;
37+
38+
public const int DI_NORMAL = 0x0003;
3339
}
3440
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace WindowTextExtractor.Native.Structs
5+
{
6+
[StructLayout(LayoutKind.Sequential)]
7+
struct CURSORINFO
8+
{
9+
public Int32 cbSize;
10+
public Int32 flags;
11+
public IntPtr hCursor;
12+
public POINTAPI ptScreenPos;
13+
}
14+
15+
[StructLayout(LayoutKind.Sequential)]
16+
struct POINTAPI
17+
{
18+
public int x;
19+
public int y;
20+
}
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace WindowTextExtractor.Native.Structs
5+
{
6+
[StructLayout(LayoutKind.Sequential)]
7+
struct ICONINFO
8+
{
9+
public bool fIcon;
10+
public Int32 xHotspot;
11+
public Int32 yHotspot;
12+
public IntPtr hbmMask;
13+
public IntPtr hbmColor;
14+
}
15+
}

WindowTextExtractor/Native/User32.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,14 @@ static class User32
9999

100100
[DllImport("user32.dll")]
101101
public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDc);
102+
103+
[DllImport("user32.dll")]
104+
public static extern bool GetCursorInfo(out CURSORINFO pci);
105+
106+
[DllImport("user32.dll")]
107+
public static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO piconinfo);
108+
109+
[DllImport("user32.dll")]
110+
public static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyHeight, int istepIfAniCur, IntPtr hbrFlickerFreeDraw, int diFlags);
102111
}
103112
}

0 commit comments

Comments
 (0)