#PB_Compiler_DPIAWARE

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

#PB_Compiler_DPIAWARE

Post by srod »

Can we have a #PB_Compiler_DPIAWARE reserved compiler constant please; similar to #PB_Compiler_Thread etc.

Thanks.
I may look like a mule, but I'm not a complete ass.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: #PB_Compiler_DPIAWARE

Post by Mistrel »

Maybe I'm missing it somewhere. Where is DPI-aware a compiler option in the IDE?
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: #PB_Compiler_DPIAWARE

Post 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).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: #PB_Compiler_DPIAWARE

Post by srod »

Yes it is in the latest beta - Windows only.
I may look like a mule, but I'm not a complete ass.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: #PB_Compiler_DPIAWARE

Post by Mistrel »

Ahh, I see. I'm still using 5.61.
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: #PB_Compiler_DPIAWARE

Post by Justin »

+1
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: #PB_Compiler_DPIAWARE

Post by Little John »

+1
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: #PB_Compiler_DPIAWARE

Post 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
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: #PB_Compiler_DPIAWARE

Post 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()
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: #PB_Compiler_DPIAWARE

Post 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
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: #PB_Compiler_DPIAWARE

Post 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)!
Et cetera is my worst enemy
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: #PB_Compiler_DPIAWARE

Post by Dude »

Why did #PB_Compiler_DpiAware get removed from the final of 5.70? It was there in the beta. :shock:
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: #PB_Compiler_DPIAWARE

Post 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!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: #PB_Compiler_DPIAWARE

Post 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. :)
I may look like a mule, but I'm not a complete ass.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: #PB_Compiler_DPIAWARE

Post 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.
Post Reply