Results 1 to 5 of 5
  1. #1
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141

    Dual/Triple Monitors vs Single Monitor Causes Initial Pop Up Modal form to open off screen

    I have found this code http://www.experts-exchange.com/Data...-monitors.html

    The idea is to establish Monitor set up and open form on Main monitor. But it is not working...
    I copied it into a Module: (My guess is I missed something... and note: the Public Declare Functions text is red)
    Code:
    Option Compare Database
    Option Explicit
     
    Public Declare Function LoadLibraryEx Lib "kernel32.dll" Alias "LoadLibraryExA" (ByVal lpFileName As String, ByVal hFile As Long, ByVal dwFlags As Long) As Long
    Public Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    Public Declare Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
    Public Declare Function FreeLibrary Lib "kernel32.dll" (ByVal hLibModule As Long) As Boolean
    Public Declare Function EnumDisplayMonitors Lib "User32.dll" (ByVal hdc As Long, ByRef lprcClip As Any, ByVal lpfnEnum As Long, ByVal dwData As Long) As Boolean
    Public Declare Function GetMonitorInfo Lib "User32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef lpmi As MONITORINFOEX) As Boolean
    Public Declare Function MonitorFromWindow Lib "User32.dll" (ByVal hWnd As Long, ByVal dwFlags As Long) As Long
     
    Public Const CCHDEVICENAME = 32
    Public Const MONITORINFOF_PRIMARY = &H1
     
    Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
     
    Public Type MONITORINFOEX
        cbSize As Long
        rcMonitor As RECT
        rcWork As RECT
        dwFlags As Long
        szDevice As String * CCHDEVICENAME
    End Type
     
    Dim MonitorId() As String
     
    Private Function PrintMonitorInfo(ForMonitorID As String) As Long
    Dim MONITORINFOEX As MONITORINFOEX
    Dim info As String
        MONITORINFOEX.cbSize = Len(MONITORINFOEX)
        If GetMonitorInfo(CLng(ForMonitorID), MONITORINFOEX) = False Then Exit Function 'Failed "GetMonitorInfo"
        With MONITORINFOEX
            With .rcWork
                PrintMonitorInfo = .Left
            End With
        End With
    End Function
     
    Public Function MonitorEnumProc(ByVal hMonitor As Long, ByVal hdcMonitor As Long, ByRef lprcMonitor As RECT, ByVal dwData As Long) As Boolean
    Dim ub As Integer
        ub = 0
        On Error Resume Next
        ub = UBound(MonitorId)
        On Error GoTo 0
        ReDim Preserve MonitorId(ub + 1)
        MonitorId(UBound(MonitorId)) = CStr(hMonitor)
        MonitorEnumProc = 1
    End Function
     
    Public Function AppLeft() As Long
    Dim hMonitor As String
    Dim i As Integer
    hMonitor = MonitorFromWindow(Application.hWndAccessApp, &H0&)
    AppLeft = PrintMonitorInfo(hMonitor)
    End Function


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    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
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    Okay I get that. The suggestion was if Vba7 then... but it said Vba7 was undefined - so I left off the vba7 if then for now.
    Still - if the form is off the main monitor and then the DB is started on single monitor unit - you can not close the form (I open to a pop up modal form)
    Here is what I have now:
    Code:
    Option Compare Database
    Option Explicit
     
    Public Declare PtrSafe Function LoadLibraryEx Lib "kernel32.dll" Alias "LoadLibraryExA" (ByVal lpFileName As String, ByVal hFile As LongLong, ByVal dwFlags As LongLong) As LongLong
    Public Declare PtrSafe Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As LongLong, ByVal lpProcName As String) As LongLong
    Public Declare PtrSafe Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As LongLong
    Public Declare PtrSafe Function FreeLibrary Lib "kernel32.dll" (ByVal hLibModule As LongLong) As Boolean
    Public Declare PtrSafe Function EnumDisplayMonitors Lib "User32.dll" (ByVal hdc As LongLong, ByRef lprcClip As Any, ByVal lpfnEnum As LongLong, ByVal dwData As LongLong) As Boolean
    Public Declare PtrSafe Function GetMonitorInfo Lib "User32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As LongLong, ByRef lpmi As MONITORINFOEX) As Boolean
    Public Declare PtrSafe Function MonitorFromWindow Lib "User32.dll" (ByVal hWnd As LongLong, ByVal dwFlags As LongLong) As LongLong
    
    Public Const CCHDEVICENAME = 32
    Public Const MONITORINFOF_PRIMARY = &H1
     
    Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
     
    Public Type MONITORINFOEX
        cbSize As Long
        rcMonitor As RECT
        rcWork As RECT
        dwFlags As Long
        szDevice As String * CCHDEVICENAME
    End Type
     
    Dim MonitorId() As String
     
    Private Function PrintMonitorInfo(ForMonitorID As String) As Long
    Dim MONITORINFOEX As MONITORINFOEX
    Dim info As String
        MONITORINFOEX.cbSize = Len(MONITORINFOEX)
        If GetMonitorInfo(CLng(ForMonitorID), MONITORINFOEX) = False Then Exit Function 'Failed "GetMonitorInfo"
        With MONITORINFOEX
            With .rcWork
                PrintMonitorInfo = .Left
            End With
        End With
    End Function
     
    Public Function MonitorEnumProc(ByVal hMonitor As Long, ByVal hdcMonitor As Long, ByRef lprcMonitor As RECT, ByVal dwData As Long) As Boolean
    Dim ub As Integer
        ub = 0
        On Error Resume Next
        ub = UBound(MonitorId)
        On Error GoTo 0
        ReDim Preserve MonitorId(ub + 1)
        MonitorId(UBound(MonitorId)) = CStr(hMonitor)
        MonitorEnumProc = 1
    End Function
     
    Public Function AppLeft() As Long
    Dim hMonitor As String
    Dim i As Integer
    hMonitor = MonitorFromWindow(Application.hWndAccessApp, &H0&)
    AppLeft = PrintMonitorInfo(hMonitor)
    End Function

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Never tried anything like this.

    What happens - error message, wrong results, nothing?
    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.

  5. #5
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    just used set autocenter to Yes on all forms

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

Similar Threads

  1. Gray Out Screen When Modal Popup
    By thebigthing313 in forum Forms
    Replies: 4
    Last Post: 07-14-2014, 10:43 AM
  2. Replies: 23
    Last Post: 07-05-2014, 08:13 AM
  3. Centering a Form within the Monitor screen
    By ashim in forum Programming
    Replies: 2
    Last Post: 04-13-2014, 02:20 PM
  4. Replies: 6
    Last Post: 08-21-2012, 11:17 AM
  5. Replies: 11
    Last Post: 06-05-2011, 09:51 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