diff --git a/Core.Window/ScreenCapture/ScreenCaptureByWGC.cs b/Core.Window/ScreenCapture/ScreenCaptureByWGC.cs index 56d3102..983257f 100644 --- a/Core.Window/ScreenCapture/ScreenCaptureByWGC.cs +++ b/Core.Window/ScreenCapture/ScreenCaptureByWGC.cs @@ -1,4 +1,5 @@ -using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Runtime.InteropServices; using System.Runtime.InteropServices.WindowsRuntime; using System.Text; using Windows.Graphics; @@ -55,6 +56,9 @@ public List GetAllScreenInfo() } public const uint WS_POPUP = 0x80000000; // 弹出窗口样式 public const uint WS_CHILD = 0x40000000; // 子窗口样式 + private const int WS_EX_TOOLWINDOW = 0x00000080; // 工具窗口 + private const int WS_EX_APPWINDOW = 0x00040000; // 应用窗口 + const int WS_EX_NOREDIRECTIONBITMAP = 0x00200000; public List GetAllWindowInfo() { var screenCaptureInfos = new List(); @@ -79,8 +83,13 @@ public List GetAllWindowInfo() { continue; } - int style = User32.GetWindowLong(currentHwnd,User32.WindowLongFlags.GWL_STYLE); - if ( (style & WS_CHILD) != 0) + int style1= User32.GetWindowLong(currentHwnd,User32.WindowLongFlags.GWL_STYLE); + if ( (style1 & (uint) User32.WindowStyles.WS_POPUP) != 0) + { + continue; + } + int style2 = User32.GetWindowLong(currentHwnd,User32.WindowLongFlags.GWL_EXSTYLE); + if ( (style2 & (int) User32.WindowStylesEx.WS_EX_NOACTIVATE) != 0||(style2 & (int) User32.WindowStylesEx.WS_EX_TOOLWINDOW) != 0) { continue; } @@ -89,6 +98,17 @@ public List GetAllWindowInfo() continue; } + User32.GetWindowDisplayAffinity(currentHwnd, out var affinity); + if (affinity!= User32.WindowDisplayAffinity.WDA_NONE) + { + continue; + } + User32.GetWindowThreadProcessId(currentHwnd,out var id); + + var s = Process.GetProcessById((int)id).ProcessName; + + + // 获取窗口标题 StringBuilder stringBuilder = new StringBuilder(100); User32.GetWindowText(currentHwnd, stringBuilder, 100); @@ -102,6 +122,7 @@ public List GetAllWindowInfo() screenCaptureInfos.Add(new WindowInfo() { Title = title, + ModuleFileName = s, Hwnd = currentHwnd.DangerousGetHandle(), Rect = new Rect(rect.X, rect.Y, rect.Width, rect.Height), ZIndex = zIndex @@ -281,23 +302,27 @@ public unsafe ScreenCaptureResult CaptureScreenBytes(ScreenCaptureInfo screenCap } case ScreenCaptureType.窗口: { - if (!User32.IsWindow(screenCaptureInfo.WindowInfo.Hwnd)) + var allWindowInfo = GetAllWindowInfo(); + if (allWindowInfo.Any(e=>e.Hwnd==screenCaptureInfo.WindowInfo.Hwnd&&e.Title==screenCaptureInfo.WindowInfo.Title&&e.ModuleFileName==screenCaptureInfo.WindowInfo.ModuleFileName)) { - var findWindow = User32.FindWindow(null,screenCaptureInfo.WindowInfo.Title); - if (findWindow.IsNull) - { - throw new Exception("目标窗口不存在"); - } - - screenCaptureInfo.WindowInfo.Hwnd = findWindow.DangerousGetHandle(); - + var monitorFromWindow = User32.MonitorFromWindow(screenCaptureInfo.WindowInfo.Hwnd,User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); + screenCaptureInfo.ScreenInfo.hMonitor = monitorFromWindow.DangerousGetHandle(); + break; } - - User32.GetWindowRect(screenCaptureInfo.WindowInfo.Hwnd, out var rect); - screenCaptureInfo.WindowInfo.Rect=new Rect(0,0,rect.Width,rect.Height); - var monitorFromWindow = User32.MonitorFromWindow(screenCaptureInfo.WindowInfo.Hwnd,User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); - screenCaptureInfo.ScreenInfo.hMonitor = monitorFromWindow.DangerousGetHandle(); - break; + else if (allWindowInfo.Any(e=>e.Title==screenCaptureInfo.WindowInfo.Title&&e.ModuleFileName==screenCaptureInfo.WindowInfo.ModuleFileName)) + { + screenCaptureInfo.WindowInfo=allWindowInfo.First(e=>e.Title==screenCaptureInfo.WindowInfo.Title&&e.ModuleFileName==screenCaptureInfo.WindowInfo.ModuleFileName); + var monitorFromWindow = User32.MonitorFromWindow(screenCaptureInfo.WindowInfo.Hwnd,User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); + screenCaptureInfo.ScreenInfo.hMonitor = monitorFromWindow.DangerousGetHandle(); + break; + }else if (allWindowInfo.Any(e=>e.ModuleFileName==screenCaptureInfo.WindowInfo.ModuleFileName)) + { + screenCaptureInfo.WindowInfo=allWindowInfo.First(e=>e.ModuleFileName==screenCaptureInfo.WindowInfo.ModuleFileName); + var monitorFromWindow = User32.MonitorFromWindow(screenCaptureInfo.WindowInfo.Hwnd,User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); + screenCaptureInfo.ScreenInfo.hMonitor = monitorFromWindow.DangerousGetHandle(); + break; + } + throw new Exception("目标窗口不存在"); } } diff --git a/Core/SDKs/CustomScenario/CustomScenario.cs b/Core/SDKs/CustomScenario/CustomScenario.cs index 4fb98a6..97c64f8 100644 --- a/Core/SDKs/CustomScenario/CustomScenario.cs +++ b/Core/SDKs/CustomScenario/CustomScenario.cs @@ -486,9 +486,14 @@ private void ParsePointItem(Dictionary threads, } catch (Exception e) { - Log.Debug(e); - ((IToastService)ServiceManager.Services.GetService(typeof(IToastService))!).Show("情景", + Log.Error("错误",e); + if (e.InnerException is not null) + { + ((IToastService)ServiceManager.Services.GetService(typeof(IToastService))!).Show("情景", + $"情景{Name}出现错误\n{e.InnerException?.Message}"); + }else ((IToastService)ServiceManager.Services.GetService(typeof(IToastService))!).Show("情景", $"情景{Name}出现错误\n{e.Message}"); + Task.Run(() => { Stop(true); }); valid = false; diff --git a/KitopiaAvalonia/Controls/Capture/DraggableResizeableControl.axaml b/KitopiaAvalonia/Controls/Capture/DraggableResizeableControl.axaml index f7e3e0b..b3e002a 100644 --- a/KitopiaAvalonia/Controls/Capture/DraggableResizeableControl.axaml +++ b/KitopiaAvalonia/Controls/Capture/DraggableResizeableControl.axaml @@ -1,6 +1,7 @@  + xmlns:capture="clr-namespace:KitopiaAvalonia.Controls.Capture" + xmlns:screenCaptureWindow="clr-namespace:KitopiaAvalonia.Converter.ScreenCaptureWindow"> @@ -11,8 +12,11 @@ + + + - + diff --git a/KitopiaAvalonia/Converter/ScreenCaptureWindow/SizeToIntegerStringConverter.cs b/KitopiaAvalonia/Converter/ScreenCaptureWindow/SizeToIntegerStringConverter.cs new file mode 100644 index 0000000..5f7f9d6 --- /dev/null +++ b/KitopiaAvalonia/Converter/ScreenCaptureWindow/SizeToIntegerStringConverter.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; + +using Avalonia; +using Avalonia.Data.Converters; + +namespace KitopiaAvalonia.Converter.ScreenCaptureWindow; + +public class SizeToIntegerStringConverter : IValueConverter +{ + private static string format="{0:F0}x{1:F0}"; + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is Size size) + { + return string.Format(format, size.Width, size.Height); + } + return string.Empty; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } +} \ No newline at end of file diff --git a/KitopiaAvalonia/Windows/ScreenCaptureWindow.axaml.cs b/KitopiaAvalonia/Windows/ScreenCaptureWindow.axaml.cs index 79e5cbc..2642922 100644 --- a/KitopiaAvalonia/Windows/ScreenCaptureWindow.axaml.cs +++ b/KitopiaAvalonia/Windows/ScreenCaptureWindow.axaml.cs @@ -266,6 +266,12 @@ protected override void OnPointerExited(PointerEventArgs e) protected override void OnPointerMoved(PointerEventArgs e) { base.OnPointerMoved(e); + var position = e.GetPosition(this); + if (Math.Pow(position.Y-_startPoint.Y,2)+ Math.Pow(position.X-_startPoint.X,2)<100) + { + return; + } + if (e.GetCurrentPoint(this) .Properties.IsLeftButtonPressed && Selecting) { @@ -310,6 +316,7 @@ protected override void OnPointerMoved(PointerEventArgs e) positionY >= e.Rect.Y && positionY <= e.Rect.Y + e.Rect.Height).OrderBy(e=>e.ZIndex).ToList(); if (firstOrDefault.Count()==0) { + _currentWindowInfo = new WindowInfo(); _startPoint = new Point(0, 0); SelectBox._dragTransform.X = 0; SelectBox._dragTransform.Y = 0; diff --git a/PluginCore b/PluginCore index c1cb6c0..f3c6718 160000 --- a/PluginCore +++ b/PluginCore @@ -1 +1 @@ -Subproject commit c1cb6c0e25dd9fc7fe525d178018f40eb1c1ce9b +Subproject commit f3c6718958d5844a86a0d0fbbdc1e7e6259f75ce