1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
Option Compare Database
Option Explicit
Private Const SM_CMONITORS As Long = 80&
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOACTIVATE As Long = &H10
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type tagMONITORINFO
cbSize As Long
rcMonitor As RECT
rcWork As RECT
dwFlags As Long
End Type
Private Declare Function GetMonitorInfo Lib "user32" _
Alias "GetMonitorInfoA" ( _
ByVal hMonitor As Long, _
ByRef tMonInfo As tagMONITORINFO) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function EnumDisplayMonitors Lib "user32" (ByVal hdc As Long, ByRef lprcClip As Any, ByVal lpfnEnum As Long, dwData As MonitorData) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _
ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Type MonitorData
MonitorForm As Access.Form
MonitorNumber As Long
End Type
'--------------------------------------------------------------
' Position un formulaire sur un moniteur
'--------------------------------------------------------------
' pForm : Formulaire à positionner
' pNumMoniteur : Numéro du moniteur
'--------------------------------------------------------------
Public Sub PosFormOnMonitor(pForm As Access.Form, Optional pNumMonitor As Long = 1)
Dim ldata As MonitorData ' Données personnalisées pour énumération
If GetSystemMetrics(SM_CMONITORS) > pNumMonitor Then Exit Sub
Set ldata.MonitorForm = pForm
ldata.MonitorNumber = pNumMonitor
EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc, ldata
End Sub
' Enumération des moniteurs
Private Function MonitorEnumProc(ByVal hMonitor As Long, ByVal hdcMonitor As Long, lprcMonitor As RECT, dwData As MonitorData) As Long
Dim lInfo As tagMONITORINFO
dwData.MonitorNumber = dwData.MonitorNumber - 1
If dwData.MonitorNumber = 0 Then
' Si moniteur demandé
' Initialise la structure
lInfo.cbSize = Len(lInfo)
' Info du moniteur
GetMonitorInfo hMonitor, lInfo
' Position le formulaire sur le moniteur
SetWindowPos dwData.MonitorForm.hwnd, 0, lInfo.rcMonitor.Left, lInfo.rcMonitor.Top, 0, 0, SWP_NOSIZE
' Sélectionne le fomumaire
DoCmd.SelectObject acForm, dwData.MonitorForm.Name
' Agrandit le formulaire
DoCmd.Maximize
' Stoppe l'énumération
MonitorEnumProc = 0
Else
' Sinon, continue l'énumération
MonitorEnumProc = 1
End If
End Function |
Partager