Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Update #16 支持设置鼠标指针是否显示
Browse files Browse the repository at this point in the history
  • Loading branch information
tylearymf committed Jan 7, 2021
1 parent 20f9475 commit 8432703
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 4 deletions.
16 changes: 13 additions & 3 deletions SETUNA/Main/CaptureForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void ShowCapture(SetunaOption.SetunaOptionData opt)
{
return;
}
Cursor.Current = Cursors.Cross;
//Cursor.Current = Cursors.Cross;
targetScreen = GetCurrentScreen();
if (targetScreen.Bounds.Width != CaptureForm.imgSnap.Width || targetScreen.Bounds.Height != CaptureForm.imgSnap.Height)
{
Expand Down Expand Up @@ -255,6 +255,7 @@ private void ThreadTask()
var flag = CaptureForm.CopyFromScreen(CaptureForm.imgSnap, new Point(targetScreen.Bounds.X, targetScreen.Bounds.Y));
if (flag)
{
Cursor.Current = Cursors.Cross;
base.Invoke(new CaptureForm.ShowFormDelegate(ShowForm));
return;
}
Expand All @@ -266,19 +267,26 @@ public static bool CopyFromScreen(Image img, Point location)
{
var result = true;
var intPtr = IntPtr.Zero;
Graphics graphics = null;
try
{
intPtr = CaptureForm.GetDC(IntPtr.Zero);
using (var graphics = Graphics.FromImage(img))
graphics = Graphics.FromImage(img);
{
var intPtr2 = IntPtr.Zero;
try
{
intPtr2 = graphics.GetHdc();
CaptureForm.BitBlt(intPtr2, 0, 0, img.Width, img.Height, intPtr, location.X, location.Y, 1087111200);

if (Mainform.Instance.optSetuna.Setuna.CursorEnabled)
{
WindowsAPI.DrawCursorImageToScreenImage(intPtr2);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw ex;
}
finally
Expand All @@ -292,11 +300,13 @@ public static bool CopyFromScreen(Image img, Point location)
}
catch (Exception ex2)
{
Console.WriteLine(ex2.Message);
Console.WriteLine(ex2);
result = false;
}
finally
{
graphics.Dispose();

if (intPtr != IntPtr.Zero)
{
CaptureForm.DeleteDC(intPtr);
Expand Down
34 changes: 34 additions & 0 deletions SETUNA/Main/Common/WindowsAPI.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;

Expand Down Expand Up @@ -123,6 +124,29 @@ public static IntPtr GetTopMostWindow(IntPtr hWnd_mainFrm)

[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);



private const int CURSOR_SHOWING = 0x00000001;
[DllImport("user32.dll")]
static extern bool GetCursorInfo(out CURSORINFO pci);
[DllImport("user32.dll")]
static extern bool DrawIcon(IntPtr hDC, int X, int Y, IntPtr hIcon);

/// <summary>
/// 将鼠标指针形状绘制到屏幕截图上
/// </summary>
/// <param name="g"></param>
public static void DrawCursorImageToScreenImage(IntPtr hDC)
{
CURSORINFO vCurosrInfo;
vCurosrInfo.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
GetCursorInfo(out vCurosrInfo);
if (vCurosrInfo.flags == CURSOR_SHOWING)
{
DrawIcon(hDC, vCurosrInfo.ptScreenPos.X, vCurosrInfo.ptScreenPos.Y, vCurosrInfo.hCursor);
}
}
}

public struct Rect
Expand All @@ -132,4 +156,14 @@ public struct Rect
public int Right { get; set; }
public int Bottom { get; set; }
}


[StructLayout(LayoutKind.Sequential)]
struct CURSORINFO
{
public int cbSize;
public int flags;
public IntPtr hCursor;
public Point ptScreenPos;
}
}
65 changes: 65 additions & 0 deletions SETUNA/Main/Option/OptionForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions SETUNA/Main/Option/OptionForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private void LoadSetunaOption()

checkBox_topMost.Checked = _so.Setuna.TopMostEnabled;
checkBox_autoStartup.Checked = Startup.AutoStartup.IsSetup();
checkBox_cursor.Checked = _so.Setuna.CursorEnabled;
}

// Token: 0x060002D5 RID: 725 RVA: 0x00013908 File Offset: 0x00011B08
Expand Down Expand Up @@ -138,6 +139,7 @@ private void WriteSetunaOption()

_so.Setuna.TopMostEnabled = checkBox_topMost.Checked;
Startup.AutoStartup.Set(checkBox_autoStartup.Checked);
_so.Setuna.CursorEnabled = checkBox_cursor.Checked;
}

// Token: 0x060002D6 RID: 726 RVA: 0x00013D84 File Offset: 0x00011F84
Expand Down Expand Up @@ -197,6 +199,7 @@ private void tabControl1_TabIndexChanged(object sender, EventArgs e)
lblMenuScrap.Font = new Font(lblMenuScrap.Font, FontStyle.Regular);
lblMenuStyle.Font = new Font(lblMenuStyle.Font, FontStyle.Regular);
lblMenuMenu.Font = new Font(lblMenuMenu.Font, FontStyle.Regular);
lblMenuMisc.Font = new Font(lblMenuMisc.Font, FontStyle.Regular);
if (tabControl1.SelectedTab == pageAll)
{
lblMenuAll.Font = new Font(lblMenuAll.Font, FontStyle.Bold);
Expand All @@ -219,6 +222,10 @@ private void tabControl1_TabIndexChanged(object sender, EventArgs e)
RefreshScrapMenuStyleList_Menu();
RefreshScrapMenuList_Menu(GetStyleIDList_Menu());
}
if (tabControl1.SelectedTab == pageMisc)
{
lblMenuMisc.Font = new Font(lblMenuMisc.Font, FontStyle.Bold);
}
}

// Token: 0x060002D9 RID: 729 RVA: 0x00014108 File Offset: 0x00012308
Expand Down Expand Up @@ -764,5 +771,20 @@ private void button2_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(Cache.CacheManager.Path);
}

private void lblMenuMisc_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = pageMisc;
}

private void lblMenuMisc_MouseEnter(object sender, EventArgs e)
{
lblComment.Text = "鼠标样式设置等等。";
}

private void lblMenuMisc_MouseLeave(object sender, EventArgs e)
{
lblComment.Text = "";
}
}
}
4 changes: 4 additions & 0 deletions SETUNA/Main/Option/SetunaOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static SetunaOption GetDefaultOption()


setunaOption.Setuna.TopMostEnabled = false;
setunaOption.Setuna.CursorEnabled = false;


var cstyle = new CStyle
Expand Down Expand Up @@ -1020,6 +1021,7 @@ public SetunaOptionData()
ClickCapture2 = false;
ClickCapture3 = false;
TopMostEnabled = false;
CursorEnabled = false;
}

// Token: 0x17000072 RID: 114
Expand Down Expand Up @@ -1098,6 +1100,8 @@ public SetunaOptionData()

public bool TopMostEnabled;

public bool CursorEnabled;

// Token: 0x02000052 RID: 82
public enum ApplicationType
{
Expand Down
2 changes: 1 addition & 1 deletion SETUNA/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("clearup")]
[assembly: NeutralResourcesLanguage("zh-CN")]
[assembly: AssemblyVersion("3.0.0.2")]
[assembly: AssemblyVersion("3.0.0.3")]

0 comments on commit 8432703

Please sign in to comment.