PureBasic Forum
http://forums.purebasic.com/english/

Detect whether PB 5.70 DPi flag is checked
http://forums.purebasic.com/english/viewtopic.php?f=3&t=72509
Page 1 of 2

Author:  Blue [ Fri Mar 22, 2019 1:57 am ]
Post subject:  Detect whether PB 5.70 DPi flag is checked

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

It's easily done with
Code:
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.

Author:  chi [ Fri Mar 22, 2019 3:08 am ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

https://www.purebasic.fr/english/viewtopic.php?p=532057#p532057
https://www.purebasic.fr/german/viewtopic.php?p=351249#p351249

Author:  Blue [ Fri Mar 22, 2019 3:17 am ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

@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.

Author:  RASHAD [ Fri Mar 22, 2019 3:33 am ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

Hi Blue
From German forum
Code:
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

Author:  Blue [ Fri Mar 22, 2019 4:27 am ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

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.

Author:  chi [ Fri Mar 22, 2019 1:21 pm ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

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

Author:  RASHAD [ Fri Mar 22, 2019 3:12 pm ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

Using Windows API
No workaround
Code:
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

Author:  Lord [ Fri Mar 22, 2019 4:12 pm ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

RASHAD wrote:
Using Windows API
No workaround
Code:
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

Author:  RASHAD [ Fri Mar 22, 2019 4:29 pm ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

Works here as expected
PB 5.70 x64
Windows 7 Ultimate x64

Quote:
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

Author:  Fred [ Fri Mar 22, 2019 5:07 pm ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

I will add a compiler constant to detected this easily.

Author:  chi [ Fri Mar 22, 2019 5:35 pm ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

Even better... thx

Author:  RASHAD [ Fri Mar 22, 2019 6:01 pm ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

Thanks Fred
According to MSDN IsProcessDPIAware() is not accurate and even GetProcessDpiAwareness() do not work properly (tested with Win 7 & Win 8.1)

Author:  Blue [ Tue Aug 27, 2019 2:48 pm ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

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 ??

Author:  Fred [ Thu Aug 29, 2019 4:32 pm ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

Just forgotten. Moved to feature request.

Author:  Andre [ Fri Mar 06, 2020 8:35 pm ]
Post subject:  Re: Detect whether PB 5.70 DPi flag is checked

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

Page 1 of 2 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/