#PB_Compiler_DPIAWARE
Posted: Sun Aug 05, 2018 1:11 pm
Can we have a #PB_Compiler_DPIAWARE reserved compiler constant please; similar to #PB_Compiler_Thread etc.
Thanks.
Thanks.
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
EnableExplicit
Procedure enumRes(hModule.i, type.i, name.i, *isDpiAware.BYTE)
Define.i hResInfo, hResData, resMem, resSize, xml
Define.i rootNode, dpiNode
Define.s nodeText
If name = 1
hresInfo = FindResource_(hModule, name, type)
hResData = LoadResource_(hModule, hResInfo)
resSize = SizeofResource_(hModule, hResInfo)
resMem = LockResource_(hResData)
xml = CatchXML(#PB_Any, resMem, resSize)
If XMLStatus(xml) = #PB_XML_Success
rootNode = RootXMLNode(xml)
dpiNode = XMLNodeFromPath(rootNode, "assembly/asmv3:application/asmv3:windowsSettings/dpiAware")
If dpiNode
nodeText = GetXMLNodeText(dpiNode)
If nodeText = "true"
*isDpiAware\b = #True
Else
*isDpiAware = #False
EndIf
Else
*isDpiAware = #False
EndIf
EndIf
FreeResource_(hResData)
ProcedureReturn #False ;stop
Else
ProcedureReturn #True ;continue
EndIf
EndProcedure
Define.b isDpiAware
EnumResourceNames_(#Null, #RT_MANIFEST, @enumRes(), @isDpiAware)
Debug isDpiAware
Code: Select all
EnableExplicit
Prototype.i ProtoIsProcessDPIAware()
Procedure.i IsDPIAware()
Protected IsProcessDPIAware.ProtoIsProcessDPIAware
Protected.i user32, dpiaware=#False
user32 = OpenLibrary(#PB_Any, "user32.dll")
If user32
IsProcessDPIAware = GetFunction(user32, "IsProcessDPIAware")
If IsProcessDPIAware
dpiaware = IsProcessDPIAware()
EndIf
CloseLibrary(user32)
EndIf
ProcedureReturn dpiaware
EndProcedure
Debug IsDPIAware()
Code: Select all
Procedure IsDpiAware()
Define.i hResInfo, hResData, resMem, resSize, xml, hModule
Define.i rootNode, dpiNode
Define.s nodeText
hModule = GetModuleHandle_(#Null)
hresInfo = FindResource_(hModule, 1, #RT_MANIFEST)
hResData = LoadResource_(hModule, hResInfo)
resSize = SizeofResource_(hModule, hResInfo)
resMem = LockResource_(hResData)
If resMem
xml = CatchXML(#PB_Any, resMem, resSize)
If xml And XMLStatus(xml) = #PB_XML_Success
rootNode = RootXMLNode(xml)
dpiNode = XMLNodeFromPath(rootNode, "assembly/asmv3:application/asmv3:windowsSettings/dpiAware")
If dpiNode
nodeText = GetXMLNodeText(dpiNode)
If nodeText = "true"
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
Else
ProcedureReturn #False
EndIf
FreeXML(xml)
EndIf
EndIf
If hResData : FreeResource_(hResData) : EndIf
ProcedureReturn #False
EndProcedure
Because "Use Windows XP Style DPI Scaling" is on by default (Win7)!Justin wrote:Your code does not work here on Win7 64, returns always true regardless of the dpi setting in compiler options.
I see. Your new code works also as expected on Windows 10. Thank you!Justin wrote:Your code does not work here on Win7 64, returns always true regardless of the dpi setting in compiler options.
For me personally, a #PB_Compiler_DPIAWARE constant would be useful for checking whether or not I had forgotten to choose the respective compiler option for that code.srod wrote:Must admit that I am simply using DesktopScaledX() etc, which even if running on a setup with anything other than 100% DPI scaling, still returns 1.0 if the DPIAware compiler option is not used. In this regards, no #PB_Compiler_DPIAWARE constant is actually required unless you want to remove the related desktop functions from your source via some conditional compilation in the case that DPIAware is not set.