screen dpi

Windows specific forum
ehowington
Enthusiast
Enthusiast
Posts: 117
Joined: Sat Sep 12, 2009 3:06 pm

screen dpi

Post by ehowington »

anyone know a short example to collect the actual screen/monitor dpi?
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: screen dpi

Post by c4s »

For Windows only:

Code: Select all

Debug GetDeviceCaps_(GetDC_(GetDesktopWindow_()), #LOGPIXELSX)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Thorium
Addict
Addict
Posts: 1308
Joined: Sat Aug 15, 2009 6:59 pm

Re: screen dpi

Post 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
Ramihyn_
Enthusiast
Enthusiast
Posts: 314
Joined: Fri Feb 24, 2006 9:40 am

Re: screen dpi

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