Detect whether PB 5.70 DPi flag is checked

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Blue
Addict
Addict
Posts: 864
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Detect whether PB 5.70 DPi flag is checked

Post by Blue »

Does anyone know of a way to detect whether PB 5.70 DPi flag is checked ?

It's easily done with

Code: Select all

is_dpiFlag_set.i = Bool(DesktopResolutionX() > 1)
Debug is_dpiFlag_set
; or 
is_dpiFlag_set = Bool(DesktopScaledX(100) > 100) 
Debug is_dpiFlag_set
when running on a system with a high DPi monitor setting , but that method will always yield False on a system with a regular dpi setting.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Detect whether PB 5.70 DPi flag is checked

Post by chi »

Et cetera is my worst enemy
User avatar
Blue
Addict
Addict
Posts: 864
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Detect whether PB 5.70 DPi flag is checked

Post by Blue »

@chi : please READ the question again.
I’m not looking for a way to check if the app is dpi aware.
I’m asking if there is a way to programmatically figure out whether the PB 5.70 dpi checkbox is checked.

Sometimes, later... :
I see that you've added a new link to your answer. The code in that one appears to be spot on.
Thank you very much, @chi, for going to the trouble of locating that piece of code on the German Forum. It does exactly what I was looking for.
Last edited by Blue on Fri Mar 22, 2019 4:53 am, edited 2 times in total.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Detect whether PB 5.70 DPi flag is checked

Post by RASHAD »

Hi Blue
From German forum

Code: Select all

CompilerIf #PB_Compiler_OS=#PB_OS_Windows
  CompilerIf #PB_Compiler_Version>=570
    Define DPIFlag.l
    EnableASM
    MOV eax,dword [PB_Compiler_DPIAware] 
    MOV DPIFlag,eax 
    If 0 = DPIFlag
      MessageRequester("Info","Compiler Option DPIAware Not checked.")
    Else
      MessageRequester("Info","Compiler Option DPIAware checked.")
    EndIf
  CompilerElse 
    CompilerError "PureBasic 5.70 Or higher version is needed."
  CompilerEndIf
CompilerEndIf
Egypt my love
User avatar
Blue
Addict
Addict
Posts: 864
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Detect whether PB 5.70 DPi flag is checked

Post by Blue »

Thank you, RASHAD.
In the absence of a compiler-style constant (à la #PB_Compiler_something), your code will do.
Let's see now if it works...

10 minutes later...
Perfect ! Exactly what I wanted.
Rashad : If you know the author of this piece of code, transmit my appreciation to him/her/it.
Last edited by Blue on Tue Aug 27, 2019 1:26 pm, edited 1 time in total.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Detect whether PB 5.70 DPi flag is checked

Post by chi »

Blue wrote:@chi : please READ the question again.
I’m not looking for a way to check if the app is dpi aware.
I’m asking if there is a way to programmatically figure out whether the PB 5.70 dpi checkbox is checked.

Sometimes, later... :
I see that you've added a new link to your answer. The code in that one appears to be spot on.
Thank you very much, @chi, for going to the trouble of locating that piece of code on the German Forum. It does exactly what I was looking for.
The day after... : You're too fast, man! I posted the second link within a few seconds ;). Anyway, glad it worked out for you...
Et cetera is my worst enemy
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Detect whether PB 5.70 DPi flag is checked

Post by RASHAD »

Using Windows API
No workaround

Code: Select all

CompilerIf #PB_Compiler_OS=#PB_OS_Windows
  CompilerIf #PB_Compiler_Version >= 570
    Lib = OpenLibrary(#PB_Any, "user32.dll")
    If Lib
      Result = CallFunction(Lib, "IsProcessDPIAware")
      CloseLibrary(Lib)
    EndIf
    If Result
      MessageRequester("Info","Compiler Option DPIAware checked.")
    Else      
      MessageRequester("Info","Compiler Option DPIAware Not checked.")
    EndIf  
  CompilerElse 
    CompilerError "PureBasic 5.70 Or higher version is needed."
  CompilerEndIf
CompilerEndIf
Egypt my love
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: Detect whether PB 5.70 DPi flag is checked

Post by Lord »

RASHAD wrote:Using Windows API
No workaround

Code: Select all

CompilerIf #PB_Compiler_OS=#PB_OS_Windows
  CompilerIf #PB_Compiler_Version >= 570
    Lib = OpenLibrary(#PB_Any, "user32.dll")
    If Lib
      Result = CallFunction(Lib, "IsProcessDPIAware")
      CloseLibrary(Lib)
    EndIf
    If Result
      MessageRequester("Info","Compiler Option DPIAware checked.")
    Else      
      MessageRequester("Info","Compiler Option DPIAware Not checked.")
    EndIf  
  CompilerElse 
    CompilerError "PureBasic 5.70 Or higher version is needed."
  CompilerEndIf
CompilerEndIf
This gives here:"Compiler Option DPIAware checked." but it is not checked in compiler options.
PB 5.70LTs(x64) on Win7 Ultimate SP 1 x64
Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Detect whether PB 5.70 DPi flag is checked

Post by RASHAD »

Works here as expected
PB 5.70 x64
Windows 7 Ultimate x64
MSDN
Return Value

Type: Type: BOOL

TRUE if the process is dpi aware; otherwise, FALSE.
Requirements

Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll
Egypt my love
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Detect whether PB 5.70 DPi flag is checked

Post by Fred »

I will add a compiler constant to detected this easily.
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Detect whether PB 5.70 DPi flag is checked

Post by chi »

Even better... thx
Et cetera is my worst enemy
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Detect whether PB 5.70 DPi flag is checked

Post by RASHAD »

Thanks Fred
According to MSDN IsProcessDPIAware() is not accurate and even GetProcessDpiAwareness() do not work properly (tested with Win 7 & Win 8.1)
Egypt my love
User avatar
Blue
Addict
Addict
Posts: 864
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Detect whether PB 5.70 DPi flag is checked

Post by Blue »

Fred wrote:I will add a compiler constant to detected this easily.
PB 5.71 LTS has been released... and I don't see any such constant in it.
So is it hidden ? or simply forgotten ??
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Detect whether PB 5.70 DPi flag is checked

Post by Fred »

Just forgotten. Moved to feature request.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Detect whether PB 5.70 DPi flag is checked

Post by Andre »

It would be very good to get such a (compiler) function with the current PB updates.
It's needed to be able to react on the current DPI-aware setting, e.g. with image sizes and their display...
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Post Reply