diff --git a/Core/Librarys/Win32API.cs b/Core/Librarys/Win32API.cs
index af85f8b60e03aaa468fb8c039b6adccceaf053d2..6a43b65021217c26f3fb8a12b02ff4daa7451d88 100644
--- a/Core/Librarys/Win32API.cs
+++ b/Core/Librarys/Win32API.cs
@@ -63,8 +63,8 @@ namespace Core.Librarys
public const UInt32 PROCESS_QUERY_INFORMATION = 0x400;
public const UInt32 PROCESS_VM_READ = 0x010;
- private const uint WINEVENT_OUTOFCONTEXT = 0;
- private const uint EVENT_SYSTEM_FOREGROUND = 3;
+ //private const uint WINEVENT_OUTOFCONTEXT = 0;
+ //private const uint EVENT_SYSTEM_FOREGROUND = 3;
public static string UWP_AppName(IntPtr hWnd, uint pID)
{
WINDOWINFO windowinfo = new WINDOWINFO();
@@ -117,8 +117,26 @@ namespace Core.Librarys
///
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool GetCursorPos(out Point lpPoint);
+ private static extern bool GetCursorPos(out POINT lpPoint);
+ [StructLayout(LayoutKind.Sequential)]
+ public struct POINT
+ {
+ public int X;
+ public int Y;
+
+ public static implicit operator Point(POINT point)
+ {
+ return new Point(point.X, point.Y);
+ }
+ }
+
+ public static Point GetCursorPosition()
+ {
+ POINT lpPoint;
+ GetCursorPos(out lpPoint);
+ return lpPoint;
+ }
#region 声音判断
///
@@ -255,5 +273,37 @@ namespace Core.Librarys
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
#endregion
+
+ #region 获取窗口信息
+ [DllImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct RECT
+ {
+ public int Left; // x position of upper-left corner
+ public int Top; // y position of upper-left corner
+ public int Right; // x position of lower-right corner
+ public int Bottom; // y position of lower-right corner
+
+ public int Width
+ {
+ get
+ {
+ return Right - Left;
+ }
+ }
+ public int Height
+ {
+ get
+ {
+ return Bottom - Top;
+ }
+ }
+
+ }
+
+ #endregion
}
}
diff --git a/Core/Servicers/Instances/Sleepdiscover.cs b/Core/Servicers/Instances/Sleepdiscover.cs
index 0220ae2b1e3190c1fc8c8cff84ff34533cb1da30..4a6e937204aa7b891d1410a0e6d33c409ed1293f 100644
--- a/Core/Servicers/Instances/Sleepdiscover.cs
+++ b/Core/Servicers/Instances/Sleepdiscover.cs
@@ -112,8 +112,7 @@ namespace Core.Servicers.Instances
{
TimeSpan timeSpan = DateTime.Now - pressKeyboardLastTime;
- Point point;
- Win32API.GetCursorPos(out point);
+ Point point = Win32API.GetCursorPosition();
if (lastPoint.ToString() == point.ToString() && timeSpan.TotalSeconds > 10)
{
// 非鼠标或键盘激活
@@ -135,7 +134,7 @@ namespace Core.Servicers.Instances
timer.Tick += Timer_Tick;
timer.Start();
- Win32API.GetCursorPos(out lastPoint);
+ lastPoint = Win32API.GetCursorPosition();
playSoundStartTime = DateTime.MinValue;
@@ -147,9 +146,7 @@ namespace Core.Servicers.Instances
private void Timer_Tick(object sender, EventArgs e)
{
- Point point;
-
- Win32API.GetCursorPos(out point);
+ Point point = Win32API.GetCursorPosition();
if (point.X + point.Y == 0)
{
@@ -227,8 +224,8 @@ namespace Core.Servicers.Instances
}
Logger.Info("【当前坐标】status:" + status + ",lastPoint:" + lastPoint.ToString() + ",now point:" + point.ToString());
+
lastPoint = point;
- //Win32API.GetCursorPos(out lastPoint);
}