Results 1 to 11 of 11
  1. #1
    jsunnb is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Location
    Southern California
    Posts
    9

    Find Users screen resolution in twips

    So I've got a database where all my forms/switchboards are done as pop-ups and the actual access application window is hidden.



    For some of the forms that pop-up, I have them size themselves to the users computer screen using this programming

    Code:
    Declare Function GetSystemMetrics32 Lib "user32" _
        Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
    
    Private Sub Form_Open(Cancel As Integer)    
        MonitorW = GetSystemMetrics32(0) * 1440 / 96
        MonitorH = GetSystemMetrics32(1) * 1440 / 96
        
        Me.Move 600, 600, MonitorW - 1200, MonitorH - 2000
    End Sub
    The problem is that I'm using the assumption that all the monitors have a dpi of 96 which I've found out isn't true. Mostly, because some of the users are older and have there text sent the larger formats in windows which evidently affect the dpi of the monitor. (I know this from my self having my monitors set at 1920x1080 and this code works, and a different user who has the exact same monitors set to 1920x1080 but with the text set to large format in windows, and the form opens larger than the monitor)

    Is there a way to just measure the monitor size in twips or find out what windows current have their dpi set to?

    Thank you for any help
    Jason

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

  4. #4
    jsunnb is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Location
    Southern California
    Posts
    9
    Well, I actually already have the code to get the screen resolution in pixels. The problem is that access sizes everything in Twips... no idea why though.
    Here is what I know:
    1 inch = 1440 Twips
    1 inch = dpi of monitor or Pixels per Inch (most monitors are 96 dpi or pixels per inch)

    to find Twip resolution of monitor you have to divide pixel resolution by dpi, then multiply by the Twips/inch

    example: 1920pix * 1440 Twips/inch
    example: 96 pix/inch
    So depending no you monitor, the number of Twips (what access uses) will change. (Monitors have different DPI and the user setting can affect DPI as well)
    And as I was saying in my post, if a user has their font made larger (see attachment) then the DPI of the screen changes (even though the resolution says they are at the max)

    So My assumption of 96dpi isn't always accurate. That's why I was hoping to find out if there was either a way to get the resolution measured in Twips or see what the current DPI is.

    Click image for larger version. 

Name:	Control Panel.jpg 
Views:	44 
Size:	106.5 KB 
ID:	10767

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Ooops, guess I should have read more carefully. You need the specs for the monitor? And also the resolution setting? That's a new one!


    Google: VBA get monitor specifications
    Sample of VB.net indicates there is a Screen class, don't know if this is translatable to VBA.
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    jsunnb is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Location
    Southern California
    Posts
    9
    I found a way to find what the user currently has their DPI set at, it's not exactly what I wanted, but with knowing their screen resolution and their DPI (and knowing that 1440 Twips / Inch is static) I can get what I wanted without the user having to set anything.

    Code:
    Private Const LOGPIXELSX As Long = 88Private Declare Function GetDeviceCaps Lib "gdi32.dll" ( _
    ByVal hdc As Long, _
    ByVal nIndex As Long) As Long
    
    Private Declare Function GetDC Lib "user32.dll" ( _
    ByVal hwnd As Long) As Long
    
    Declare Function ReleaseDC Lib "user32.dll" ( _
    ByVal hwnd As Long, _
    ByVal hdc As Long) As Long
    
    Public Function GetDpi() As Long
    Dim hdcScreen As Long
    Dim iDPI As Long
    iDPI = -1
    hdcScreen = GetDC(0)
    If (hdcScreen) Then
    iDPI = GetDeviceCaps(hdcScreen, LOGPIXELSX)
    ReleaseDC 0, hdcScreen
    End If
    GetDpi = iDPI
    End Function

  7. #7
    PeterCole is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2024
    Posts
    1

    Version that works for 32 and 64-bit Access 2010 and later.

    Code:
    'Version that will work with 32-bit and 64-Bit version. PtrSafe added and some Long variables defined as LongPtr
    
    Private Const LOGPIXELSX As Long = 88
    Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32.dll" ( _
    ByVal hdc As LongPtr, _
    ByVal nIndex As Long) As Long
    
    
    Private Declare PtrSafe Function GetDC Lib "user32.dll" ( _
    ByVal hwnd As LongPtr) As Long
    
    
    Declare PtrSafe Function ReleaseDC Lib "user32.dll" ( _
    ByVal hwnd As LongPtr, _
    ByVal hdc As LongPtr) As Long
    
    
    
    
    Public Function GetDpi() As Long
    Dim hdcScreen As LongPtr
    Dim iDPI As Long
      iDPI = -1
      hdcScreen = GetDC(0)
      If (hdcScreen) Then
        iDPI = GetDeviceCaps(hdcScreen, LOGPIXELSX)
        ReleaseDC 0, hdcScreen
      End If
      GetDpi = iDPI
    End Function

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    Always worth checking how old the thread is - 11years in this case. Better to start a new thread - perhaps in the programming forum

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    IMO not entirely a bad thing when a question is not being asked, but instead a solution or update is given. It could help anyone who stumbles on this in a search. I probably would not start a new thread and link to this one either, unless I had a question.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    Glad it was a short thread. Unfortunately I tried the code and it reported 96 dpi. Changed text to 150% and still 96 dpi.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    DPI depends on hardware but is almost always 96
    It does not change when either resolution or scaling factor is changed.
    In fact all that increasing the scaling factor does is reduce the effective resolution.

    In fact, in my automatic form resizing application, I set the DPI as a constant = 96. See Automatic Form Resizing - 3 (isladogs.co.uk)
    In over 15 years of using this on numerous machines, including those with default scaling = 125%. I have never needed to alter it ... but I provide the option if needed.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 04-30-2013, 05:44 PM
  2. Log-in Screen
    By imintrouble in forum Forms
    Replies: 8
    Last Post: 10-11-2011, 04:24 AM
  3. Replies: 11
    Last Post: 06-05-2011, 09:51 PM
  4. resizing form based on resolution
    By Jerry8989 in forum Forms
    Replies: 4
    Last Post: 10-09-2009, 08:55 AM
  5. Adjusting Form size based on screen resolution
    By stombiztalker in forum Forms
    Replies: 0
    Last Post: 02-17-2009, 07:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums