0

I want to implement the access form to get the left right top bottom of the second screen through the window api for the calculation of the appbar when change scale display, but when I use Microsoft Access Runtime 2013 "GetMonitorInfo" to get the value of the current screen, the result is completely different from Microsoft Access. Is this normal? Is this the affect by the structure of Microsoft Access runtime? Why is it still affected by Microsoft Access runtime and Microsoft Access when using the window api directly?

Code

    ' 1.) Get current monitor hwnd from current form position
    lngCurrentMonitorHWnd = MonitorFromWindow(frmAccessForm.hwnd, MONITOR_DEFAULTTONULL)

    ' 2) Get current monitor info and logical size
    objCurrentMonitorInfo.cbSize = Len(objCurrentMonitorInfo)
    Call GetMonitorInfo(lngCurrentMonitorHWnd, objCurrentMonitorInfo)

    ' 3) Set current monitor info variable value
    mlngCurrentScreenLeft = objCurrentMonitorInfo.rcMonitor.Left
    mlngCurrentScreenRight = objCurrentMonitorInfo.rcMonitor.Right
    mlngCurrentScreenTop = objCurrentMonitorInfo.rcMonitor.Top
    mlngCurrentScreenBottom = objCurrentMonitorInfo.rcMonitor.Bottom

Result of Microsoft Access 365/2019/2016/2013

100%

Scale 100%

125%

Scale 125%

Result of Microsoft Access Runtime 2013

100%

Scale 100%

125%

Scale 125%

Ways I've tried

  1. Change MonitorFromWindow window handle property to window native file explorer (get by api-sam.exe), by pass acees hwnd to get monitor hwnd. but result still different in Microsoft Office runtime 2013
    ' 1.) Get current monitor hwnd from current form position
    lngCurrentMonitorHWnd = MonitorFromWindow(69911, MONITOR_DEFAULTTONULL)

    ' 2) Get current monitor info and logical size
    objCurrentMonitorInfo.cbSize = Len(objCurrentMonitorInfo)
    Call GetMonitorInfo(lngCurrentMonitorHWnd, objCurrentMonitorInfo)

2.Change way to get monitor hwnd,use MonitorFromPoint to get current screen hwnd,but result still different in Microsoft Office runtime 2013.

    ' 1.) Get current monitor hwnd from current mouse position
    GetCursorPos objMousePoint   
    lngCurrentMonitorHWnd = MonitorFromPoint(objMousePoint.x, objMousePoint.y,MONITOR_DEFAULTTOPRIMARY)

    ' 2) Get current monitor info and logical size
    objCurrentMonitorInfo.cbSize = Len(objCurrentMonitorInfo)
    Call GetMonitorInfo(lngCurrentMonitorHWnd, objCurrentMonitorInfo)
Chau Chun
  • 95
  • 1
  • 6
  • 4
    Its probably a hi-dpi issue. Since you're running in-process with Access (I think), then your code is subject to Access hi-dpi rules (whatever they are). It's quite complex matter, check out this article here, it's about VSTO, but I think it's relevant: https://learn.microsoft.com/en-us/office/client-developer/ddpi/handle-high-dpi-and-dpi-scaling-in-your-office-solution what you want to do is create your own DPI aware context and run your code inside that. – Simon Mourier Dec 08 '22 at 07:18
  • What *DPI aware* are your application and the destination application? see [the answer](https://stackoverflow.com/a/68429403/15511041) for some research. – YangXiaoPo-MSFT Dec 08 '22 at 07:38
  • 2
    It's a known issue that Access VBA has trouble reading hi-res monitors correctly because of some variables declared as Integer, not Long. Also, there is no date or known plan for fixing this. – Gustav Dec 08 '22 at 10:35

0 Answers0