Page 1 of 1

screen dpi

Posted: Mon Nov 28, 2011 5:57 am
by ehowington
anyone know a short example to collect the actual screen/monitor dpi?

Re: screen dpi

Posted: Mon Nov 28, 2011 10:27 am
by c4s
For Windows only:

Code: Select all

Debug GetDeviceCaps_(GetDC_(GetDesktopWindow_()), #LOGPIXELSX)

Re: screen dpi

Posted: Thu Dec 01, 2011 8:29 am
by Thorium

Code: Select all

;retrieves the horizontal DPI of the desktop
Procedure.i Gui_GetDesktopDpiX()

  Protected hDc.i
  Protected hDpi.i
  
  hDc = GetDC_(GetDesktopWindow_())
  If hDc
    hDpi = GetDeviceCaps_(hDc, #LOGPIXELSX)
    ReleaseDC_(GetDesktopWindow_(), hDc)
  EndIf

  ProcedureReturn hDpi

EndProcedure

;retrieves the vertical DPI of the desktop
Procedure.i Gui_GetDesktopDpiY()
  
  Protected hDc.i
  Protected vDpi.i
  
  hDc = GetDC_(GetDesktopWindow_())
  If hDc
    vDpi = GetDeviceCaps_(hDc, #LOGPIXELSY)
    ReleaseDC_(GetDesktopWindow_(), hDc)
  EndIf
  
  ProcedureReturn vDpi

EndProcedure
And here is a example of how to resize a window to a physical size:
It resizes a window to the physical iPhone screen size (not resolution).
It's from a editor for a iPhone game i was working on.

Code: Select all

;resizes the 3D view window to the iPhone screen size
Procedure Gui_Resize3DWnd2iPhoneSize(Scale.f)

  Protected Width.i
  Protected Height.i
  Protected RelationX.f
  Protected RelationY.f
  
  RelationX = Gui_GetDesktopDpiX() / #iPhone_xDpi
  RelationY = Gui_GetDesktopDpiY() / #iPhone_yDpi
  
  Width  = #iPhone_Width * RelationX * Scale
  Height = #iPhone_Height * RelationY * Scale

  ResizeWindow(Gui_3DWnd\PbNum, #PB_Ignore, #PB_Ignore, Width, Height)

EndProcedure

Re: screen dpi

Posted: Thu Dec 01, 2011 8:59 am
by Ramihyn_
Btw. there seems hardly any display where the horizontal and vertical DPI settings are different. I was wondering about this when i did some application code for DPI scaling and it seems like it only affects a few cases where a manufacturer puts a 16:9 panel into a 16:10 case.

It seems really rare and the differences are small when it happens.