Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
wpf
提交
d21ce7a8
W
wpf
项目概览
dotNET Platform
/
wpf
11 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wpf
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d21ce7a8
编写于
1月 03, 2022
作者:
T
ThomasGoulet73
提交者:
GitHub
1月 03, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Migrate DPI awareness initialization to managed (#5765)
上级
c52adfb9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
71 deletion
+25
-71
src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/main.cpp
src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/main.cpp
+0
-65
src/Microsoft.DotNet.Wpf/src/PresentationCore/ModuleInitializer.cs
...soft.DotNet.Wpf/src/PresentationCore/ModuleInitializer.cs
+25
-6
未找到文件。
src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/main.cpp
浏览文件 @
d21ce7a8
...
...
@@ -39,24 +39,6 @@ using namespace System::Diagnostics;
// code in this Assembly when the assembly is loaded into any AppDomain.
//
//
// We want to call SetProcessDPIAware from user32.dll only on machines
// running Vista or later OSs. We provide our own declaration (the
// original is in winuser.h) here so we can specify the DllImport attribute
// which allows delayed loading of the function - thereby allowing us to
// run on pre-Vista OSs.
//
[
DllImport
(
"user32.dll"
,
EntryPoint
=
"SetProcessDPIAware"
)]
WINUSERAPI
BOOL
WINAPI
SetProcessDPIAware_Internal
(
VOID
);
#define WINNT_VISTA_VERSION 0x06
namespace
MS
{
namespace
Internal
{
private
ref
class
NativeWPFDLLLoader
sealed
{
...
...
@@ -121,7 +103,6 @@ public:
// Constructor of class CModuleInitialize
__declspec
(
noinline
)
CModuleInitialize
(
void
(
*
cleaningUpFunc
)())
{
IsProcessDpiAware
();
MS
::
Internal
::
NativeWPFDLLLoader
::
LoadDwrite
();
// Initialize some global arrays.
...
...
@@ -159,52 +140,6 @@ public:
{
return
MS
::
Internal
::
NativeWPFDLLLoader
::
GetDWriteCreateFactoryFunctionPointer
();
}
private
:
//
// A private helper method to handle the DpiAwareness issue for current application.
// This method is set as noinline since the MC++ compiler may otherwise inline it in a
// Security Transparent method which will lead to a security violation where the transparent
// method will be calling security critical code in this method.
//
__declspec
(
noinline
)
void
IsProcessDpiAware
(
)
{
Version
^
osVersion
=
(
Environment
::
OSVersion
)
->
Version
;
if
(
osVersion
->
Major
<
WINNT_VISTA_VERSION
)
{
// DPIAware feature is available only in Vista and after.
return
;
}
//
// Below code is only for Vista and newer platform.
//
Assembly
^
assemblyApp
;
Type
^
disableDpiAwareType
=
System
::
Windows
::
Media
::
DisableDpiAwarenessAttribute
::
typeid
;
bool
bDisableDpiAware
=
false
;
// By default, Application is DPIAware.
assemblyApp
=
Assembly
::
GetEntryAssembly
();
// Check if the Application has explicitly set DisableDpiAwareness attribute.
if
(
assemblyApp
!=
nullptr
&&
Attribute
::
IsDefined
(
assemblyApp
,
disableDpiAwareType
))
{
bDisableDpiAware
=
true
;
}
if
(
!
bDisableDpiAware
)
{
// DpiAware composition is enabled for this application.
SetProcessDPIAware_Internal
(
);
}
// Only when DisableDpiAwareness attribute is set in Application assembly,
// It will ignore the SetProcessDPIAware API call.
}
};
void
CleanUp
();
...
...
src/Microsoft.DotNet.Wpf/src/PresentationCore/ModuleInitializer.cs
浏览文件 @
d21ce7a8
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
internal
static
class
ModuleInitializer
{
...
...
@@ -15,11 +13,32 @@ internal static class ModuleInitializer
/// operations are carried out. To do this, we simply call LoadDwrite
/// as the module constructor for DirectWriteForwarder would do this anyway.
/// </summary>
#
pragma
warning
disable
CA2255
#pragma warning disable CA2255
[
ModuleInitializer
]
public
static
void
Initialize
()
{
IsProcessDpiAware
();
MS
.
Internal
.
NativeWPFDLLLoader
.
LoadDwrite
();
}
#
pragma
warning
restore
CA2255
#pragma warning restore CA2255
private
static
void
IsProcessDpiAware
()
{
// By default, Application is DPIAware.
Assembly
assemblyApp
=
Assembly
.
GetEntryAssembly
();
// Check if the Application has explicitly set DisableDpiAwareness attribute.
if
(
assemblyApp
!=
null
&&
Attribute
.
IsDefined
(
assemblyApp
,
typeof
(
System
.
Windows
.
Media
.
DisableDpiAwarenessAttribute
)))
{
// DpiAware composition is enabled for this application.
SetProcessDPIAware_Internal
();
}
// Only when DisableDpiAwareness attribute is set in Application assembly,
// It will ignore the SetProcessDPIAware API call.
}
[
DllImport
(
"user32.dll"
,
EntryPoint
=
"SetProcessDPIAware"
)]
private
static
extern
void
SetProcessDPIAware_Internal
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录