Re: How do I get the SCALE directly from Windows?
Posted: Fri Aug 27, 2021 11:25 am
Maybe like this :>
Gets the current DPI factor of the Monitor our Window is on:
Gets the current DPI factor of the Monitor our Window is on:
Code: Select all
EnableExplicit
Procedure.i GetMonitorDPI(Window.i,*FactorX.Double,*FactorY.Double)
Protected *api
Protected *proc
Protected hmonitor.i
Protected dpi_x.i
Protected dpi_y.i
*api = Ascii("GetDpiForMonitor")
If *api
*proc = GetProcAddress_(LoadLibrary_("shcore.dll"),*api)
FreeMemory(*api)
If *proc
hmonitor = MonitorFromWindow_(WindowID(Window),#MONITOR_DEFAULTTONEAREST)
If CallFunctionFast(*proc,hmonitor,#Null,@dpi_x,@dpi_y) = #S_OK
*FactorX\d = dpi_x / 96.0
*FactorY\d = dpi_y / 96.0
ProcedureReturn #True
EndIf
EndIf
EndIf
ProcedureReturn #False
EndProcedure
Procedure.i Main()
Protected factor_x.d
Protected factor_y.d
If OpenWindow(0,0,0,960,600,#Null$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
Debug GetMonitorDPI(0,@factor_x,@factor_y)
Debug factor_x
Debug factor_y
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
CloseWindow(0)
EndIf
ProcedureReturn #Null
EndProcedure
Main()
End