From 95c0a045aa5b3d83d2cb656ded7e24b7287cd82c Mon Sep 17 00:00:00 2001 From: Xu Date: Sun, 16 Jun 2024 17:57:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BC=A9=E6=94=BE=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E9=94=80=E6=AF=81=E5=89=8D=E6=B8=85=E7=90=86=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E5=8F=8A=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E6=B8=85=E7=90=86=E7=AA=97=E5=8F=A3=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/Interact with Magpie programally.md | 4 +++ ...70\216 Magpie \344\272\244\344\272\222.md" | 4 +++ src/Magpie.Core/ScalingWindow.cpp | 27 +++++++++++++++++++ src/Magpie.Core/ScalingWindow.h | 2 ++ 4 files changed, 37 insertions(+) diff --git a/docs/Interact with Magpie programally.md b/docs/Interact with Magpie programally.md index 1c2523c2..1158236b 100644 --- a/docs/Interact with Magpie programally.md +++ b/docs/Interact with Magpie programally.md @@ -91,3 +91,7 @@ Magpie stops scaling when the foreground window changes, with some system window ```c++ SetProp(hYourWindow, L"Magpie.ToolWindow", (HANDLE)TRUE); ``` + +### Notes + +According to the [documentation](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setpropw), you should use RemoveProp to clear this property before your window is destroyed. However, if you forget to do so, there's no need to worry: [the system will automatically clean it up](https://devblogs.microsoft.com/oldnewthing/20231030-00/?p=108939). diff --git "a/docs/\344\273\245\347\274\226\347\250\213\346\226\271\345\274\217\344\270\216 Magpie \344\272\244\344\272\222.md" "b/docs/\344\273\245\347\274\226\347\250\213\346\226\271\345\274\217\344\270\216 Magpie \344\272\244\344\272\222.md" index af9de50d..33c0fc87 100644 --- "a/docs/\344\273\245\347\274\226\347\250\213\346\226\271\345\274\217\344\270\216 Magpie \344\272\244\344\272\222.md" +++ "b/docs/\344\273\245\347\274\226\347\250\213\346\226\271\345\274\217\344\270\216 Magpie \344\272\244\344\272\222.md" @@ -91,3 +91,7 @@ destRect.bottom = (LONG)(INT_PTR)GetProp(hwndScaling, L"Magpie.DestBottom"); ```c++ SetProp(hYourWindow, L"Magpie.ToolWindow", (HANDLE)TRUE); ``` + +### 注意事项 + +根据[文档](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setpropw)的要求,你应该在你的窗口被销毁前使用 RemoveProp 清理这个属性。但如果你忘了也不会有问题,[系统会自动清理它](https://devblogs.microsoft.com/oldnewthing/20231030-00/?p=108939)。 diff --git a/src/Magpie.Core/ScalingWindow.cpp b/src/Magpie.Core/ScalingWindow.cpp index d59448b5..8dc335ae 100644 --- a/src/Magpie.Core/ScalingWindow.cpp +++ b/src/Magpie.Core/ScalingWindow.cpp @@ -438,6 +438,8 @@ LRESULT ScalingWindow::_MessageHandler(UINT msg, WPARAM wParam, LPARAM lParam) n // 还原时钟精度 timeEndPeriod(1); + _RemoveWindowProps(); + // 广播停止缩放 PostMessage(HWND_BROADCAST, WM_MAGPIE_SCALINGCHANGED, 0, 0); break; @@ -617,6 +619,31 @@ void ScalingWindow::_SetWindowProps() const noexcept { SetProp(_hWnd, L"Magpie.DestBottom", (HANDLE)(INT_PTR)destRect.bottom); } +// 文档要求窗口被销毁前清理所有属性,但实际上这不是必须的,见 +// https://devblogs.microsoft.com/oldnewthing/20231030-00/?p=108939 +void ScalingWindow::_RemoveWindowProps() const noexcept { + RemoveProp(_hWnd, L"Magpie.SrcHWND"); + RemoveProp(_hWnd, L"Magpie.SrcLeft"); + RemoveProp(_hWnd, L"Magpie.SrcTop"); + RemoveProp(_hWnd, L"Magpie.SrcRight"); + RemoveProp(_hWnd, L"Magpie.SrcBottom"); + RemoveProp(_hWnd, L"Magpie.DestLeft"); + RemoveProp(_hWnd, L"Magpie.DestTop"); + RemoveProp(_hWnd, L"Magpie.DestRight"); + RemoveProp(_hWnd, L"Magpie.DestBottom"); + + if (_options.IsTouchSupportEnabled()) { + RemoveProp(_hWnd, L"Magpie.SrcTouchLeft"); + RemoveProp(_hWnd, L"Magpie.SrcTouchTop"); + RemoveProp(_hWnd, L"Magpie.SrcTouchRight"); + RemoveProp(_hWnd, L"Magpie.SrcTouchBottom"); + RemoveProp(_hWnd, L"Magpie.DestTouchLeft"); + RemoveProp(_hWnd, L"Magpie.DestTouchTop"); + RemoveProp(_hWnd, L"Magpie.DestTouchRight"); + RemoveProp(_hWnd, L"Magpie.DestTouchBottom"); + } +} + // 在源窗口四周创建辅助窗口拦截黑边上的触控点击。 // // 直接将 srcRect 映射到 destRect 是天真的想法。似乎可以创建一个全屏的背景窗口来屏 diff --git a/src/Magpie.Core/ScalingWindow.h b/src/Magpie.Core/ScalingWindow.h index be74faf8..b68521ec 100644 --- a/src/Magpie.Core/ScalingWindow.h +++ b/src/Magpie.Core/ScalingWindow.h @@ -73,6 +73,8 @@ class ScalingWindow : public WindowBase { void _SetWindowProps() const noexcept; + void _RemoveWindowProps() const noexcept; + void _CreateTouchHoleWindows() noexcept; winrt::DispatcherQueue _dispatcher{ nullptr };