Skip to content

Commit

Permalink
Fea #64, 为slint提供Windows XP运行支持
Browse files Browse the repository at this point in the history
* 添加 DwmEnableBlurBehindWindow
* 添加 IsProcessDPIAware
* 添加 GetWindowDisplayAffinity
* 添加 SetWindowDisplayAffinity
* 添加 RegisterTouchWindow
* 添加 UnregisterTouchWindow
* 添加 IsTouchWindow
* 添加 GetTouchInputInfo
* 添加 CloseTouchInputHandle
  • Loading branch information
mingkuang-Chuyu committed Oct 4, 2023
1 parent b039048 commit 8b3d2b0
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: https://EditorConfig.org


# 代码文件尽可能的使用 UTF-8,因为英语字符占据大多数。
# 数据文件比如 XML,json统一缩进 2,因为外部规范往往如此

[*]
end_of_line = crlf
insert_final_newline = true
charset = utf-8-bom
indent_style = space
indent_size = 4

[*.{vcxproj,xml}]
indent_style = space
indent_size = 2
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=crlf

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
14 changes: 14 additions & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
| BluetoothGATTSetCharacteristicValue | 不存在时,返回ERROR_NOT_SUPPORTED。
| BluetoothGATTSetDescriptorValue | 不存在时,返回ERROR_NOT_SUPPORTED。

## dwmapi.dll
| 函数 | Fallback
| ---- | -----------
| DwmEnableBlurBehindWindow | 不存在时,返回 `DWM_E_COMPOSITIONDISABLED`(表示DWM已禁用)。

## iphlpapi.dll
| 函数 | Fallback
| ---- | -----------
Expand Down Expand Up @@ -388,6 +393,15 @@
| SystemParametersInfoForDpi | 不存在时,调用SystemParametersInfoW。
| RegisterSuspendResumeNotification | 不存在时,使用窗口模拟。
| UnregisterSuspendResumeNotification | 不存在时,内部实现。
| IsProcessDPIAware | 不存在时,返回 FALSE。
| SetProcessDPIAware | 不存在时,什么都不做,假装成功。
| GetWindowDisplayAffinity | 不存在时,TRUE,并报告窗口没有任何保护`WDA_NONE`
| SetWindowDisplayAffinity | 不存在时,什么都不做,假装成功。
| RegisterTouchWindow | 不存在时,什么都不做,假装成功。
| UnregisterTouchWindow | 不存在时,什么都不做,假装成功。
| IsTouchWindow | 不存在时,始终报告非触摸窗口。
| GetTouchInputInfo | 不存在时,报告错误 ERROR_INVALID_HANDLE。
| CloseTouchInputHandle | 不存在时,报告错误 ERROR_INVALID_HANDLE。

## userenv.dll
| 函数 | Fallback
Expand Down
1 change: 1 addition & 0 deletions src/Thunks/YY_Thunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define _YY_APPLY_TO_LATE_BOUND_MODULES(_APPLY) \
_APPLY(ntdll, "ntdll" , USING_UNSAFE_LOAD ) \
_APPLY(kernel32, "kernel32" , USING_UNSAFE_LOAD ) \
_APPLY(dwmapi, "dwmapi" , 0 ) \
_APPLY(psapi, "psapi" , 0 ) \
_APPLY(pdh, "pdh" , 0 ) \
_APPLY(version, "version" , 0 ) \
Expand Down
31 changes: 31 additions & 0 deletions src/Thunks/dwmapi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <dwmapi.h>

namespace YY
{
namespace Thunks
{
#if (YY_Thunks_Support_Version < NTDDI_WIN6)

// 最低受支持的客户端 Windows Vista [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008[仅限桌面应用]
__DEFINE_THUNK(
dwmapi,
8,
HRESULT,
STDAPICALLTYPE,
DwmEnableBlurBehindWindow,
HWND _hWnd,
_In_ const DWM_BLURBEHIND* _pBlurBehind
)
{
if (const auto _pfnDwmEnableBlurBehindWindow = try_get_DwmEnableBlurBehindWindow())
{
return _pfnDwmEnableBlurBehindWindow(_hWnd, _pBlurBehind);
}

// 老版本系统不支持Dwm,因此假装此功能被禁用
return DWM_E_COMPOSITIONDISABLED;
}
#endif
}
}
204 changes: 199 additions & 5 deletions src/Thunks/user32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,29 @@ namespace YY
return FALSE;
}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN6)

// 最低受支持的客户端 Windows Vista [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008[仅限桌面应用]
__DEFINE_THUNK(
user32,
0,
BOOL,
WINAPI,
IsProcessDPIAware,
void)
{
if (const auto _pfnIsProcessDPIAware = try_get_IsProcessDPIAware())
{
return _pfnIsProcessDPIAware();
}

// XP 无法感知DPI,返回的Rect始终被系统缩放了。
return FALSE;
}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN6)
Expand All @@ -74,10 +97,8 @@ namespace YY
return pSetProcessDPIAware();
}

/*
* 如果函数不存在,说明这个是一个XP或者更低版本,对于这种平台。
* DPI感知是直接打开的,所以我们直接返回TRUE 即可。
*/
// 假装成功,其实我们都知道,我们没有成功……
// XP系统无法感知 DPI
return TRUE;
}
#endif
Expand Down Expand Up @@ -448,6 +469,179 @@ namespace YY
}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN7)

// 最低受支持的客户端 Windows 7 [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008 R2[仅限桌面应用]
__DEFINE_THUNK(
user32,
8,
BOOL,
WINAPI,
GetWindowDisplayAffinity,
_In_ HWND _hWnd,
_Out_ DWORD* _pdwAffinity)
{
if (auto const _pfnGetWindowDisplayAffinity = try_get_GetWindowDisplayAffinity())
{
return _pfnGetWindowDisplayAffinity(_hWnd, _pdwAffinity);
}

if (!_pdwAffinity)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}

// 系统不支持,假装自己不需要任何保护
*_pdwAffinity = WDA_NONE;
return TRUE;
}
#endif

#if (YY_Thunks_Support_Version < NTDDI_WIN7)

// 最低受支持的客户端 Windows 7 [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008 R2[仅限桌面应用]
__DEFINE_THUNK(
user32,
8,
BOOL,
WINAPI,
SetWindowDisplayAffinity,
_In_ HWND _hWnd,
_In_ DWORD _dwAffinity)
{
if (auto const _pfnSetWindowDisplayAffinity = try_get_SetWindowDisplayAffinity())
{
return _pfnSetWindowDisplayAffinity(_hWnd, _dwAffinity);
}

// 系统不支持,假装自己成功……
return TRUE;
}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN7)

// 最低受支持的客户端 Windows 7 [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008 R2[仅限桌面应用]
__DEFINE_THUNK(
user32,
8,
BOOL,
WINAPI,
RegisterTouchWindow,
_In_ HWND _hWnd,
_In_ ULONG _ulFlags)
{
if (auto const _pfnRegisterTouchWindow = try_get_RegisterTouchWindow())
{
return _pfnRegisterTouchWindow(_hWnd, _ulFlags);
}

return TRUE;
}
#endif

#if (YY_Thunks_Support_Version < NTDDI_WIN7)

// 最低受支持的客户端 Windows 7 [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008 R2[仅限桌面应用]
__DEFINE_THUNK(
user32,
4,
BOOL,
WINAPI,
UnregisterTouchWindow,
_In_ HWND _hWnd)
{
if (auto const _pfnUnregisterTouchWindow = try_get_UnregisterTouchWindow())
{
return _pfnUnregisterTouchWindow(_hWnd);
}

return TRUE;
}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN7)

// 最低受支持的客户端 Windows 7 [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008 R2[仅限桌面应用]
__DEFINE_THUNK(
user32,
8,
BOOL,
WINAPI,
IsTouchWindow,
_In_ HWND _hWnd,
_Out_opt_ PULONG _puFlags)
{
if (auto const _pfnIsTouchWindow = try_get_IsTouchWindow())
{
return _pfnIsTouchWindow(_hWnd, _puFlags);
}

if (_puFlags)
*_puFlags = 0;

return TRUE;
}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN7)

// 最低受支持的客户端 Windows 7 [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008 R2[仅限桌面应用]
__DEFINE_THUNK(
user32,
16,
BOOL,
WINAPI,
GetTouchInputInfo,
_In_ HTOUCHINPUT _hTouchInput,
_In_ UINT _uInputs,
_Out_writes_(_uInputs) PTOUCHINPUT _pInputs,
_In_ int _cbSize)
{
if (auto const _pfnGetTouchInputInfo = try_get_GetTouchInputInfo())
{
return _pfnGetTouchInputInfo(_hTouchInput, _uInputs, _pInputs, _cbSize);
}

// 老版本系统没有触摸消息,_hTouchInput 必然无效
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
#endif

#if (YY_Thunks_Support_Version < NTDDI_WIN7)

// 最低受支持的客户端 Windows 7 [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008 R2[仅限桌面应用]
__DEFINE_THUNK(
user32,
4,
BOOL,
WINAPI,
CloseTouchInputHandle,
_In_ HTOUCHINPUT _hTouchInput)
{
if (auto const _pfnCloseTouchInputHandle = try_get_CloseTouchInputHandle())
{
return _pfnCloseTouchInputHandle(_hTouchInput);
}

// 老版本系统没有触摸消息,_hTouchInput 必然无效
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
#endif
}//namespace Thunks

} //namespace YY
} //namespace YY
1 change: 1 addition & 0 deletions src/YY-Thunks.UnitTest/YY-Thunks.UnitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<ClInclude Include="..\Thunks\api-ms-win-power-base.hpp" />
<ClInclude Include="..\Thunks\bcrypt.hpp" />
<ClInclude Include="..\Thunks\bluetoothapis.hpp" />
<ClInclude Include="..\Thunks\dwmapi.hpp" />
<ClInclude Include="..\Thunks\ext-ms-win-ntuser-powermanagement.hpp" />
<ClInclude Include="..\Thunks\ext-ms-win-ntuser-window.hpp" />
<ClInclude Include="..\Thunks\Iphlpapi.hpp" />
Expand Down
3 changes: 3 additions & 0 deletions src/YY-Thunks.UnitTest/YY-Thunks.UnitTest.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@
<ClInclude Include="..\Thunks\ntdll.hpp">
<Filter>Thunks</Filter>
</ClInclude>
<ClInclude Include="..\Thunks\dwmapi.hpp">
<Filter>Thunks</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\def\x86\PSAPI2Kernel32.def">
Expand Down

0 comments on commit 8b3d2b0

Please sign in to comment.