[BUG-v573 or Windows10?] Another DPI question...

Windows specific forum
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

[BUG-v573 or Windows10?] Another DPI question...

Post by skywalk »

Can someone explain why Resolution does not change with [±] DPI Aware?
Also, why are my 2nd and 3rd desktops 4 and 5 and not in correct order?
Meaning, 2nd display is actually DISPLAY5?
My reason for this question is to position some frequently used app's at startup, similar to this thread.

Code: Select all

#CMA$ = ","
nDesktops = ExamineDesktops() - 1
Debug "DesktopName" + #CMA$ + "Width" + #CMA$ + "Height" + #CMA$ +
      "ResolutionX" + #CMA$ + "ResolutionY" + #CMA$ + 
      "X" + #CMA$ + "Y"
For i = 0 To nDesktops
  DTn$ = DesktopName(i)
  Debug DesktopName(i) + #CMA$ + Str(DesktopWidth(i)) + #CMA$ + Str(DesktopHeight(i)) + #CMA$ +
        StrD(DesktopResolutionX()) + #CMA$ + StrD(DesktopResolutionY()) + #CMA$ + 
        Str(DesktopX(i)) + #CMA$ + Str(DesktopY(i))
Next i
;[ ] DPI Aware
; DesktopName,Width,Height,ResolutionX,ResolutionY,X,Y
; \\.\DISPLAY1,1920,1080,1,1,0,0
; \\.\DISPLAY4,1920,1080,1,1,-13,-2160
; \\.\DISPLAY5,1920,1080,1,1,-13,-1080
;[x] DPI Aware
; DesktopName,Width,Height,ResolutionX,ResolutionY,X,Y
; \\.\DISPLAY1,1920,1080,1.25,1.25,0,0
; \\.\DISPLAY4,1920,1080,1.25,1.25,-13,-2160
; \\.\DISPLAY5,1920,1080,1.25,1.25,-13,-1080
EDIT: StrD() for DesktopResolutionXY(), thanks JHPJHP :)
Last edited by skywalk on Tue Mar 16, 2021 10:37 pm, edited 1 time in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: [BUG-v573 or Windows10?] Another DPI question...

Post by JHPJHP »

Hi skywalk,
skywalk wrote:... why are my 2nd and 3rd desktops 4 and 5 and not in correct order?
Not sure if the following gives different results; currently only using a single monitor.
- make sure DPI Aware is checked

Windows Services & Other Stuff\Other_Stuff\Other_Stuff\MonitorStuff\GetMonitorInfo.pb
Last edited by JHPJHP on Tue Mar 16, 2021 11:06 pm, edited 1 time in total.
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: [BUG-v573 or Windows10?] Another DPI question...

Post by skywalk »

Thanks JHPJHP!
Updated my 1st post and now curious why DesktpResolutionX | Y() is the same for all displays?
Only Display 1 is 125%. The other 2 are 100%.
The debug output was DPI Aware ON & OFF.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

[BUG-v573 or Windows10?] Another DPI question...

Post by JHPJHP »

Hi skywalk,

I don't believe the DPI Aware compiler option applies to multiple desktops, but I could be wrong.

I thought I read somewhere on the forum a request for DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2.

I wrote the following as an include. It doesn't resolve the per monitor issue with PureBasic commands, but it allows for per monitor scaling.
- make sure DPI Aware is unchecked

Windows Services & Other Stuff\Other_Stuff\Other_Stuff\MonitorStuff\SetDpiAwareness.pbi
Last edited by JHPJHP on Wed Mar 17, 2021 12:11 pm, edited 1 time in total.
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: [BUG-v573 or Windows10?] Another DPI question...

Post by Rinzwind »

Actually the constants are:

#DPI_AWARENESS_CONTEXT_UNAWARE = $6010 ;24592
#DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = $7811 ;30737 ;$9011 ;36881
#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = $12 ;18
#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = $22 ;34
#DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = $40006010 ;1073766416

(it's not a simple integer value, but a pointer to a static structure or whatever... I double checked by comparing with results from GetWindowDpiAwarenessContext() and you can also check with task manager after setting it in code (tab details, add column DPI Awareness).

Code: Select all

#define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name

#define _DPI_AWARENESS_CONTEXTS_

DECLARE_HANDLE(DPI_AWARENESS_CONTEXT);

typedef enum DPI_AWARENESS {
    DPI_AWARENESS_INVALID           = -1,
    DPI_AWARENESS_UNAWARE           = 0,
    DPI_AWARENESS_SYSTEM_AWARE      = 1,
    DPI_AWARENESS_PER_MONITOR_AWARE = 2
} DPI_AWARENESS;

#define DPI_AWARENESS_CONTEXT_UNAWARE               ((DPI_AWARENESS_CONTEXT)-1)
#define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE          ((DPI_AWARENESS_CONTEXT)-2)
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE     ((DPI_AWARENESS_CONTEXT)-3)
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2  ((DPI_AWARENESS_CONTEXT)-4)
#define DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED     ((DPI_AWARENESS_CONTEXT)-5)
Not that it helps much, you have to do the scaling all yourself then and disable DPI aware in compiler settings. Hence the bug report (technically feature implementation request)...

Code: Select all

EnableExplicit

Global _User32 = OpenLibrary(#PB_Any, "User32.dll")
If _User32
  #DPI_AWARENESS_CONTEXT_UNAWARE = $6010 ;24592
  #DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = $9011 ;36881
  #DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = $12 ;18
  #DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = $22 ;34
  #DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = $40006010 ;1073766416
  Prototype SetProcessDpiAwarenessContext(value)
  Prototype GetWindowDpiAwarenessContext(hwnd)
  Global SetProcessDpiAwarenessContext_.SetProcessDpiAwarenessContext = GetFunction(_User32, "SetProcessDpiAwarenessContext")
  Global GetWindowDpiAwarenessContext_.GetWindowDpiAwarenessContext = GetFunction(_User32, "GetWindowDpiAwarenessContext") 
EndIf



SetProcessDpiAwarenessContext_(#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)

OpenWindow(0, 0, 0, 400, 300, "Test")
Define dpic = GetWindowDpiAwarenessContext_(WindowID(0))
Debug dpic
Debug #DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
ButtonGadget(0, 10, 10, 60, 21, "Test")
Define e

Repeat
  e = WaitWindowEvent()
Until e = #PB_Event_CloseWindow

;task manager says 'Per-Monitor (v2)'
(it won't do any scaling, just shows that the process dpi awareness is set to DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, tested on both 32 and 64 bit PB)

Possibly useful to some:

Code: Select all

Procedure GetDPI(hwnd = 0, *p.POINT = 0)
  Protected hmon, dpiX = 96, dpiY = 96
  If *p
    hmon = MonitorFromPoint_(PeekQ(*p), #MONITOR_DEFAULTTONULL)
  EndIf
  If Not hmon
    hmon = MonitorFromWindow_(hwnd, #MONITOR_DEFAULTTOPRIMARY)
  EndIf
  If hmon
    If GetDpiForMonitor_(hmon, #MDT_EFFECTIVE_DPI, @dpiX, @dpiY) = #S_OK
      ;
    EndIf
  EndIf
  ProcedureReturn dpiX
EndProcedure

Procedure.f GetScale(hwnd = 0, *p.POINT = 0)
  ProcedureReturn GetDPI(hwnd, *p) / 96
EndProcedure
Last edited by Rinzwind on Wed Jan 19, 2022 7:36 am, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: [BUG-v573 or Windows10?] Another DPI question...

Post by JHPJHP »

Hi Rinzwind,

Based on some additional reading and after various tests, I don't believe the DPI Awareness constants you posted should be relied on.
NOTE: Currently this is only conjecture based on some unsubstantiated documentation and a few personal tests.

The following Microsoft constants work correctly and can be verified using the include file listed below.

Updated Windows Services & Other Stuff\Other_Stuff\MonitorStuff\includes\SetDpiAwareness.pbi

Code: Select all

#DPI_AWARENESS_CONTEXT_UNAWARE              = -1
#DPI_AWARENESS_CONTEXT_SYSTEM_AWARE         = -2
#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE    = -3
#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = -4
#DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED    = -5
Last edited by JHPJHP on Fri Sep 24, 2021 6:50 pm, edited 6 times in total.
breeze4me
Enthusiast
Enthusiast
Posts: 511
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: [BUG-v573 or Windows10?] Another DPI question...

Post by breeze4me »

While searching for the value "DPI_AWARENESS_CONTEXT", I found the following article.
I think this could be helpful.

https://stackoverflow.com/questions/502 ... -the-other
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: [BUG-v573 or Windows10?] Another DPI question...

Post by Rinzwind »

JHPJHP wrote: Wed Mar 17, 2021 12:20 pm Hi Rinzwind,

Based on some additional reading and after various tests, I don't believe the DPI Awareness constants you posted should be relied on.
NOTE: Currently this is only conjecture based on some unsubstantiated documentation and a few personal tests.

The following Microsoft constants work correctly and can be verified using the include file listed below.

Updated Windows Services & Other Stuff\Other_Stuff\MonitorStuff\includes\SetDpiAwareness.pbi

Code: Select all

#DPI_AWARENESS_CONTEXT_UNAWARE              = -1
#DPI_AWARENESS_CONTEXT_SYSTEM_AWARE         = -2
#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE    = -3
#DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = -4
#DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED    = -5
These also do seem to work, but subsequently calling GetWindowDpiAwarenessContext_ returns the other values I posted (although it seems #DPI_AWARENESS_CONTEXT_SYSTEM_AWARE changed from 36881 to 30737 so yeah who knows why this is so messed up... https://stackoverflow.com/questions/417 ... i/41709591)
Post Reply