Results 1 to 5 of 5
  1. #1
    smbrush is offline Experienced Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2018
    Posts
    30

    Detect screen resolution of the monitor where my Access app is running

    I'm developing an Access application for users who have a multi-monitor environment, usually two screens. One is the screen of a laptop while the other is a regular monitor. Typically, the two monitors have different screen resolutions and so an app designed for one screen won't look right on the other. The form objects will appear off center and will be too big or small.

    To solve this problem, I've added code to a function called by an AutoExec macro which will detect the screen resolution, calculate a numeric factor, and multiply it with the left properties of the objects of each of the forms of the app to position them in the center of the screen. So far, all the API functions I've used can only detect the resolution of the primary monitor, the laptop. Here are my attempts to code this (the declarations of each of these API functions are made in the Declaration section of the module):

    nScreenWidth = GetSystemMetrics(SM_CXSCREEN)
    This only gets the width of the primary monitor, the laptop.

    hwnd = hWndAccessApp
    nNumMonitors = GetSystemMetrics(SM_CMONITORS)
    If nNumMonitors > 1 Then
    hMonitor = MonitorFromWindow(hwnd, 0&) 'Returns current monitor
    Else
    hMonitor = hwnd
    End If
    hDCcaps = WM_apiGetDC(hMonitor)
    nScreenWidth= WM_apiGetDeviceCaps(hDCcaps, WM_HORZRES)
    The problem here is that GetDC() calculates 0 when hMonitor is not the handle of the primary screen so that GetDeviceCaps() also returns 0.



    Can anyone recommend a way to code this successfully?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    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
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Two things that may be helpful

    1. The attached utility obtains the resolution of both monitors and allow you to play around with various settings
    By design when it opens, only one button is enabled, the mouse cursor is bound by the form and all desktop icons & images are hidden.
    Don't panic - they are all easily restored by clicking form buttons!

    Click image for larger version. 

Name:	MultiMonitors v2.png 
Views:	19 
Size:	73.8 KB 
ID:	36512

    2. I handle issues with different monitor size/resolution by using free open source form resizing code by Jamie Czernak.
    Other similar code is available but most has to be paid for...

    Many of my example apps include this code in a module called modResize
    The code itself is complex but the implementation is simple.
    Just add one line of code to the Form_Load event of each form you want to resize automatically:
    Code:
    ResizeForm Me
    Its a LOT easier than trying to code it all yourself ....

    You can find one example including this code on my website: http://www.mendipdatasystems.co.uk/c...ace/4594365418

    HTH
    Attached Files Attached Files
    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

  4. #4
    smbrush is offline Experienced Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2018
    Posts
    30
    Thank you to June7 and Ridders52 for responding to my question. However, none of these code examples is telling me what I need to know. I need to know how to determine which monitor in a multi-monitor environment my Access app is running on and what the screen resolution of that monitor is.

    I'd appreciate it if someone can respond to this thread with code that can accomplish this.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    The previous example will tell you the resolution of each connected monitor
    The attached will tell you which monitor it is opened on (as well as allow you to modify the brightness/contrast on some monitors)
    The latter part may cause an error on some monitors but you only want the first part

    So take the relevant code from each example (or use form resizing code and make your life much easier!)
    Attached Files Attached Files
    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. Find Users screen resolution in twips
    By jsunnb in forum Programming
    Replies: 10
    Last Post: 03-20-2024, 05:44 PM
  2. Replies: 1
    Last Post: 08-26-2017, 01:15 PM
  3. Centering a Form within the Monitor screen
    By ashim in forum Programming
    Replies: 2
    Last Post: 04-13-2014, 02:20 PM
  4. Fitting to Screen Resolution
    By Mahendra1000 in forum Access
    Replies: 4
    Last Post: 11-28-2013, 05:58 AM
  5. Adjusting Form size based on screen resolution
    By stombiztalker in forum Forms
    Replies: 0
    Last Post: 02-17-2009, 07:18 PM

Tags for this Thread

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