diff --git a/Ink Canvas.sln.DotSettings.user b/Ink Canvas.sln.DotSettings.user index 5ef2d60..61f8f81 100644 --- a/Ink Canvas.sln.DotSettings.user +++ b/Ink Canvas.sln.DotSettings.user @@ -1,2 +1,5 @@  - WARNING \ No newline at end of file + WARNING + <AssemblyExplorer> + <Assembly Path="D:\vs\ica\InkCanvasForClass\IAWinFX.dll" /> +</AssemblyExplorer> \ No newline at end of file diff --git a/InkCanvasForClass/InkCanvasForClass.csproj.user b/InkCanvasForClass/InkCanvasForClass.csproj.user index 0e5f0de..a711d86 100644 --- a/InkCanvasForClass/InkCanvasForClass.csproj.user +++ b/InkCanvasForClass/InkCanvasForClass.csproj.user @@ -20,9 +20,6 @@ Code - - Code - @@ -46,9 +43,6 @@ Designer - - Designer - Designer diff --git a/InkCanvasForClass/MainWindow.xaml b/InkCanvasForClass/MainWindow.xaml index da19815..a386e9c 100644 --- a/InkCanvasForClass/MainWindow.xaml +++ b/InkCanvasForClass/MainWindow.xaml @@ -7802,9 +7802,9 @@ - { + // 排除被過濾的窗體句柄 if (excluded.Contains(new HWND(hwnd))) return true; + + // 判斷窗體是否可見 var isvisible = IsWindowVisible(hwnd); if (!isvisible) return true; + + // 判斷窗體透明度和額外樣式 var windowLong = (int)GetWindowLongPtr(hwnd, -20); GetLayeredWindowAttributes(hwnd, out uint crKey, out byte bAlpha, out uint dwFlags); if ((windowLong & 0x00000080L) != 0) return true; if ((windowLong & 0x00080000) != 0 && (dwFlags & 0x00000002) != 0 && bAlpha == 0) return true; //分层窗口且全透明 - DwmGetWindowAttribute(hwnd, (int)DwmWindowAttribute.Cloaked, out bool isCloacked, Marshal.SizeOf(typeof(bool))); + + // Win8+專用,用於檢測UWP應用是否隱藏 + bool isCloacked = false; + if (OSVersion.GetOperatingSystem() > OperatingSystem.Windows7) + DwmGetWindowAttribute(hwnd, (int)DwmWindowAttribute.Cloaked, out isCloacked, Marshal.SizeOf(typeof(bool))); + if (isCloacked) return true; + + // 獲取窗體實際大小 DwmGetWindowAttribute(hwnd, DwmWindowAttribute.ExtendedFrameBounds, out RECT realRect, Marshal.SizeOf(typeof(RECT))); + + // 獲取窗體的進程ID var pidRes = GetWindowThreadProcessId(hwnd, out uint pid); if (pid == 0 || pidRes == 0) return true; + + // 獲取窗體的DPI差異,scale為1則代表非DWM強制拉伸顯示窗體,實際截圖會根據窗體的DPI Awareness來截取 var dpiForHwnd = GetDpiForWindow(hwnd); var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static); var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static); @@ -441,26 +457,39 @@ namespace Ink_Canvas { if (dpi > dpiForHwnd) { // 说明该应用是win32应用,靠DWM的拉伸放大到高DPI scale = dpi / (double)dpiForHwnd; } - if (isCloacked) return true; + + // 獲取窗體應用程式圖標 var icon = GetAppIcon(hwnd); + + // 獲取應用程式標題,這裡空標題不略過,用於後續繼續判斷獲取標題 var length = GetWindowTextLength(hwnd) + 1; var title = new StringBuilder(length); GetWindowText(hwnd, title, length); // if (title.ToString().Length == 0) return true; - // 這裡懶得做 Alt Tab窗口的校驗了,直接窗體標題黑名單 + + + // 窗體標題黑名單,在黑名單中的窗體不會顯示 if (excludedWindowTitle.Equals(title.ToString())) return true; - RECT rect; + + // 獲取窗體狀態,如果是最小化就跳過 WINDOWPLACEMENT placement = new WINDOWPLACEMENT(); GetWindowPlacement(hwnd, ref placement); if (placement.showCmd == 2) return true; + + // 獲取窗口Rect,用於和DwmGetWindowAttribute方法獲取到的窗體大小進行Offset計算 + RECT rect; GetWindowRect(hwnd, out rect); var w = rect.Width; var h = rect.Height; if (w == 0 || h == 0) return true; + + // 使用PrintWindow(RENDER_FULL_CONTENT)來實現窗體圖片截取(支持D3D和DX) Bitmap bmp = new Bitmap(rect.Width, rect.Height); Graphics memoryGraphics = Graphics.FromImage(bmp); IntPtr hdc = memoryGraphics.GetHdc(); PrintWindow(hwnd, hdc, 2); + + // 添加窗體信息 windows.Add(new WindowInformation() { AppIcon = icon, Title = title.ToString(), @@ -478,7 +507,11 @@ namespace Ink_Canvas { SystemDPI = dpi, DPIScale = scale }); + + // 釋放HDC memoryGraphics.ReleaseHdc(hdc); + + // 嘗試調用GC回收叻色 System.GC.Collect(); System.GC.WaitForPendingFinalizers(); return true; diff --git a/InkCanvasForClass/MainWindow_cs/MW_SettingsToLoad.cs b/InkCanvasForClass/MainWindow_cs/MW_SettingsToLoad.cs index 73bb32d..1afc42e 100644 --- a/InkCanvasForClass/MainWindow_cs/MW_SettingsToLoad.cs +++ b/InkCanvasForClass/MainWindow_cs/MW_SettingsToLoad.cs @@ -103,6 +103,7 @@ namespace Ink_Canvas { AdministratorPrivilegeIndicateText.Text = "icc目前以非管理员身份运行"; RunAsAdminButton.Visibility = Visibility.Visible; RunAsUserButton.Visibility = Visibility.Collapsed; + CannotSwitchToUserPrivNotification.IsOpen = false; } } catch (Exception e) { diff --git a/InkCanvasForClass/Popups/ScreenshotWindow.xaml b/InkCanvasForClass/Popups/ScreenshotWindow.xaml index 4578541..74bde1c 100644 --- a/InkCanvasForClass/Popups/ScreenshotWindow.xaml +++ b/InkCanvasForClass/Popups/ScreenshotWindow.xaml @@ -191,7 +191,7 @@ - + diff --git a/InkCanvasForClass/Popups/ScreenshotWindow.xaml.cs b/InkCanvasForClass/Popups/ScreenshotWindow.xaml.cs index 2913021..6855f7e 100644 --- a/InkCanvasForClass/Popups/ScreenshotWindow.xaml.cs +++ b/InkCanvasForClass/Popups/ScreenshotWindow.xaml.cs @@ -24,10 +24,12 @@ using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Shell; using System.Xml.Linq; +using OSVersionExtension; using Vanara.PInvoke; using Color = System.Windows.Media.Color; using Shell32; using static Ink_Canvas.MainWindow; +using OperatingSystem = OSVersionExtension.OperatingSystem; namespace Ink_Canvas.Popups { @@ -51,6 +53,10 @@ namespace Ink_Canvas.Popups SelectionIcon, DesktopIcon }; + + WindowIcon.IsHitTestVisible = OSVersion.GetOperatingSystem() >= OperatingSystem.Windows10; + WindowIcon.Opacity = OSVersion.GetOperatingSystem() >= OperatingSystem.Windows10 ? 1 : 0.5; + foreach (var b in iconList) { b.MouseLeave += IconMouseLeave; diff --git a/InkCanvasForClass/Popups/WindowScreenshotGridWindow.xaml b/InkCanvasForClass/Popups/WindowScreenshotGridWindow.xaml deleted file mode 100644 index f2f4350..0000000 --- a/InkCanvasForClass/Popups/WindowScreenshotGridWindow.xaml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/InkCanvasForClass/Popups/WindowScreenshotGridWindow.xaml.cs b/InkCanvasForClass/Popups/WindowScreenshotGridWindow.xaml.cs deleted file mode 100644 index df77fe7..0000000 --- a/InkCanvasForClass/Popups/WindowScreenshotGridWindow.xaml.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Interop; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; -using iNKORE.UI.WPF.Modern.Controls; -using Vanara.PInvoke; - -namespace Ink_Canvas.Popups -{ - /// - /// WindowScreenshotGridWindow.xaml 的交互逻辑 - /// - public partial class WindowScreenshotGridWindow : Window - { - - private BitmapImage BitmapToImageSource(Bitmap bitmap) - { - using (MemoryStream memory = new MemoryStream()) - { - bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp); - memory.Position = 0; - BitmapImage bitmapimage = new BitmapImage(); - bitmapimage.BeginInit(); - bitmapimage.StreamSource = memory; - bitmapimage.CacheOption = BitmapCacheOption.OnLoad; - bitmapimage.EndInit(); - - return bitmapimage; - } - } - - private static ImageSource IconToImageSource(Icon icon) - { - ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon( - icon.Handle, - Int32Rect.Empty, - BitmapSizeOptions.FromEmptyOptions()); - - return imageSource; - } - - private class Win { - public string Title { get; set; } - public BitmapImage Bitmap { get; set; } - public ImageSource Icon { get; set; } - public HWND Handle { get; set; } - public Bitmap OriginBitmap { get; set; } - } - - private MainWindow mainWindow; - - private ObservableCollection _windows = new ObservableCollection(); - - public WindowScreenshotGridWindow(MainWindow.WindowInformation[] wins, MainWindow mainWindow) { - InitializeComponent(); - WindowsItemControl.ItemsSource = _windows; - foreach (var windowInformation in wins) { - _windows.Add(new Win() { - Title = windowInformation.Title, - Bitmap = BitmapToImageSource(windowInformation.WindowBitmap), - Handle = windowInformation.hwnd, - OriginBitmap = windowInformation.WindowBitmap, - Icon = IconToImageSource(windowInformation.AppIcon) - }); - Trace.WriteLine(windowInformation.Title); - } - - this.mainWindow = mainWindow; - } - - protected override void OnClosed(EventArgs e) { - base.OnClosed(e); - _windows.Clear(); - } - - private void WindowItem_MouseUp(object sender, MouseButtonEventArgs e) { - var item = ((SimpleStackPanel)sender).Tag as Win; - string savePath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); - item.OriginBitmap.Save(savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".bmp", ImageFormat.Bmp); - } - } -}