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?