以下代码来自
Windows 10 Anniversary Update SDK.我需要常量句柄才能在Delphi中使用API,因为截至今天,Delphi中不包含这些头文件.
DECLARE_HANDLE(DPI_AWARENESS_CONTEXT); #define DPI_AWARENESS_CONTEXT_UNAWARE ((DPI_AWARENESS_CONTEXT)-1) #define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ((DPI_AWARENESS_CONTEXT)-2) #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ((DPI_AWARENESS_CONTEXT)-3)
当我在各种DPI场景中使用GetThreadDpiAwarenessContext时,我已经了解了NativeUInts的值:
DPI_AWARENESS_CONTEXT_UNAWARE = 16; DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = 17; DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = 18;
但我想100%肯定这些价值观是面向未来的.它们在SetThreadDpiAwarenessContext通话中工作并具有预期效果,但我不清楚这些值是如何得出的.除了显式整数声明之外,我无法在Delphi中复制产生这些结果的头部构造.
解决方法
要在
SetThreadDpiAwarenessContext中使用,您应将其声明为
type DPI_AWARENESS_CONTEXT = type THandle; const DPI_AWARENESS_CONTEXT_UNAWARE = DPI_AWARENESS_CONTEXT(-1); DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = DPI_AWARENESS_CONTEXT(-2); DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE= DPI_AWARENESS_CONTEXT(-3);
但是当您从GetThreadDpiAwarenessContext获得响应时,您需要在收到的值上使用GetAwarenessFromDpiAwarenessContext并将其与@L_404_6@枚举进行比较.
您不能直接比较DPI_AWARENESS_CONTEXT,因为它包含多条信息,Microsoft可能会在将来更改它.