Page 1 of 2

#PB_Compiler_DPIAWARE

Posted: Sun Aug 05, 2018 1:11 pm
by srod
Can we have a #PB_Compiler_DPIAWARE reserved compiler constant please; similar to #PB_Compiler_Thread etc.

Thanks.

Re: #PB_Compiler_DPIAWARE

Posted: Sun Aug 05, 2018 7:22 pm
by Mistrel
Maybe I'm missing it somewhere. Where is DPI-aware a compiler option in the IDE?

Re: #PB_Compiler_DPIAWARE

Posted: Sun Aug 05, 2018 10:09 pm
by Dude
You're using the latest beta, right? It's in there. (I don't have it installed anymore, but I saw it when I had it).

Re: #PB_Compiler_DPIAWARE

Posted: Mon Aug 06, 2018 8:03 am
by srod
Yes it is in the latest beta - Windows only.

Re: #PB_Compiler_DPIAWARE

Posted: Wed Aug 08, 2018 10:17 pm
by Mistrel
Ahh, I see. I'm still using 5.61.

Re: #PB_Compiler_DPIAWARE

Posted: Tue Nov 13, 2018 1:36 pm
by Justin
+1

Re: #PB_Compiler_DPIAWARE

Posted: Fri Jan 25, 2019 12:03 pm
by Little John
+1

Re: #PB_Compiler_DPIAWARE

Posted: Fri Jan 25, 2019 10:30 pm
by Justin
A quick workaround, before waiting two years for a constant:

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

Re: #PB_Compiler_DPIAWARE

Posted: Fri Jan 25, 2019 11:05 pm
by Little John
Your code works fine here with PB 5.70 LTS on Windows 10, thank you!

A bit shorter: :-)

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()

Re: #PB_Compiler_DPIAWARE

Posted: Fri Jan 25, 2019 11:34 pm
by Justin
Your code does not work here on Win7 64, returns always true regardless of the dpi setting in compiler options.
A bit simpler version of my previous code without the enum callback:

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

Re: #PB_Compiler_DPIAWARE

Posted: Sat Jan 26, 2019 1:21 am
by chi
Justin wrote:Your code does not work here on Win7 64, returns always true regardless of the dpi setting in compiler options.
Because "Use Windows XP Style DPI Scaling" is on by default (Win7)!

Re: #PB_Compiler_DPIAWARE

Posted: Sat Jan 26, 2019 1:27 am
by Dude
Why did #PB_Compiler_DpiAware get removed from the final of 5.70? It was there in the beta. :shock:

Re: #PB_Compiler_DPIAWARE

Posted: Sat Jan 26, 2019 8:26 am
by Little John
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!

Re: #PB_Compiler_DPIAWARE

Posted: Sat Jan 26, 2019 12:28 pm
by srod
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.

Having said that, nice code Justin. Works well here, though of course it is not a compile time option. That nicely answers a question of mine which I hadn't gotten around to asking, namely does setting the DPIAware option actually set the 'dpiAware' app manifest option for use by Win 8.1 and Win 10? I can see it does now which is just as well as DPI virtualization would otherwise have caused a major problem. :)

Re: #PB_Compiler_DPIAWARE

Posted: Sat Jan 26, 2019 1:16 pm
by Little John
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.
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. :-)

Also, using such a constant would make the code more self documenting. This is especially important when exchanging code here on the forum, so that other users just can copy, paste and run it. Otherwise, the person who posts the code would have to write a concerning remark, which can easily be forgotten.
That said, the person who writes the code can do without the constant #PB_Compiler_DPIAWARE (deliberately or not), even when it does exist. :-)
So for optimal self-documentation of the code, I really would appreciate it if DPI awareness (and other things as well) could be switched on and off ONLY be using a respective constant in the code.