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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
Option Compare Database
Option Explicit
'********************* Code Start **********************************
'The code related to the Removal of Min/Max/Close button in reports*
'was originally written by Terry Kreft & Keri Hardwick. *
'*******************************************************************
Private Type RECT ' 16 Bytes
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Declare Function apiGetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) _
As Long
Private Declare Function apiSetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
Private Declare Function apiGetWindowRect Lib "user32" _
Alias "GetWindowRect" _
(ByVal hwnd As Long, _
lpRect As RECT) _
As Long
Private Declare Function apiGetSystemMetrics Lib "user32" _
Alias "GetSystemMetrics" _
(ByVal nIndex&) _
As Long
Private Declare Function apiReleaseDC Lib "user32" _
Alias "ReleaseDC" _
(ByVal hwnd As Long, _
ByVal hDC As Long) _
As Long
Private Declare Function apiGetDeviceCaps Lib "Gdi32" _
Alias "GetDeviceCaps" _
(ByVal hDC As Long, _
ByVal nIndex As Long) _
As Long
Private Declare Function apiGetDC Lib "user32" _
Alias "GetDC" _
(ByVal hwnd As Long) _
As Long
Private Declare Function IsZoomed Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Private Declare Function MoveWindow Lib "user32" _
(ByVal hwnd As Long, _
ByVal x As Long, _
ByVal Y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Private Declare Function GetParent Lib "user32" _
(ByVal hwnd As Long) As Long
'Use following instead of GetWindowRect
Private Declare Function GetClientRect Lib "user32" _
(ByVal hwnd As Long, _
lpRect As RECT) As Long
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNORMAL = 1
Private Const GWL_EXSTYLE = -20
Private Const GWL_HINSTANCE = -6
Private Const GWL_HWNDPARENT = -8
Private Const GWL_ID = -12
Private Const GWL_STYLE = -16
Private Const GWL_USERDATA = -21
Private Const GWL_WNDPROC = -4
Private Const WS_CAPTION = &HC00000
Private Const WS_SYSMENU = &H80000
Private Const SM_CYCAPTION = 4 ' Height of caption or title
Private Const TWIPSPERINCH = 1440
'** Window Style Constants
Private Const WS_DLGFRAME& = &H400000
Private Const WS_THICKFRAME& = &H40000
'Début de section pour les Types nécessaires à la fonction ModifierMarges
Type ch_DEVMODE
RGB As String * 94
End Type
Type type_DEVMODE
chNomPériphérique As String * 16
entSpécVersion As Integer
entVersionGestionnaire As Integer
entTaille As Integer
entExtraGestionnaire As Integer
lngChamps As Long
entOrientation As Integer
entTaillePapier As Integer
entLongueurPapier As Integer
entLargeurPapier As Integer
entEchelle As Integer
entCopies As Integer
entSourceDéfaut As Integer
entQualitéImpression As Integer
entCouleur As Integer
entRectoverso As Integer
entResolution As Integer
entOptionTT As Integer
entAssembler As Integer
entNomFormulaire As String * 16
lngPad As Long
lngBits As Long
lngPW As Long
lngPH As Long
lngDFI As Long
lngDFr As Long
End Type
Type ch_PRTMIP
chRGB As String * 28
End Type
Type type_PRTMIP
entMargeGauche As Long
entMargeHaut As Long
entMargeDroite As Long
entMargeBas As Long
entDonnéesSeulement As Long
entLargeur As Long
entHauteur As Long
entTailleDesEléments As Long
entColonnes As Long
entEspacementDeColonnes As Long
entEspacementDeLignes As Long
entDisposition As Long
entImpressionRapide As Long
entFeuilleDeDonnées As Long
End Type
'Fin de section pour les Types nécessaires à la fonction ModifierMarges
Public Sub ModifierMarges(txtNom As String, lngHaut As Long, lngBas As Long, lngGauche As Long, lngDroite As Long)
' Modifier les marges d'un rapport avant de l'imprimer
' paramètres : 1- le nom du rapport en texte
' 2- la marge du haut en cm
' 3- la marge du bas en cm
' 4- la marge du gauche en cm
' 5- la marge du droite en cm
' exemple :
' ModifierMarges "Contacts", 1, 1, 1.5, 1.5
' DoCmd.OpenReport "Contacts", acViewPreview
Dim ChaînePrtMip As ch_PRTMIP
Dim PM As type_PRTMIP
Dim rpt As Report
DoCmd.OpenReport txtNom, acDesign ' Ouvre l'état en mode Création.
Set rpt = Reports(txtNom)
ChaînePrtMip.chRGB = rpt.PrtMip
LSet PM = ChaînePrtMip
PM.entMargeHaut = lngHaut * 567 ' Définit les marges.
PM.entMargeBas = lngBas * 567
PM.entMargeGauche = lngGauche * 567
PM.entMargeDroite = lngDroite * 567
LSet ChaînePrtMip = PM ' Met à jour la propriété.
rpt.PrtMip = ChaînePrtMip.chRGB
DoCmd.Save
End Sub
Private Sub MaximizeRestoredReport(R As Report)
'This code was originally written by Terry Kreft
'Full credits and acknowledgements to him.
'
Dim MDIRect As RECT
' If the Report is maximized, restore it.
If IsZoomed(R.hwnd) <> 0 Then
ShowWindow R.hwnd, SW_SHOWNORMAL
End If
' Get the screen coordinates and window size of the
' MDIClient area.
'This is the line which is different
GetClientRect GetParent(R.hwnd), MDIRect
' Move the Report to the upper left corner of the MDIClient
' window (0,0) and size it to the same size as the
' MDIClient window.
MoveWindow R.hwnd, 0, 0, MDIRect.right - MDIRect.left, _
MDIRect.bottom - MDIRect.top, True
End Sub
Sub sRemoveCaption(rpt As Report)
Dim lngRet As Long, lngStyle As Long
Dim tRECT As RECT, lngX As Long
Dim lngCaptionWidth As Long
Dim lngLeft As Long
Dim lngTop As Long
Dim lngWidth As Long
Dim lngHeight As Long
lngRet = apiGetWindowLong(rpt.hwnd, GWL_STYLE)
lngStyle = (lngRet Xor WS_DLGFRAME Xor _
WS_THICKFRAME) And Not WS_CAPTION
'Need the Xor above to keep window from being sizable
lngRet = apiSetWindowLong(rpt.hwnd, GWL_STYLE, lngStyle)
lngX = apiGetWindowRect(rpt.hwnd, tRECT)
'have to resize the form now
'how much was caption's screenspace
lngCaptionWidth = apiGetSystemMetrics(SM_CYCAPTION)
With tRECT
lngLeft = .left
lngTop = .top
lngWidth = .right - .left
lngHeight = .bottom - .top - lngCaptionWidth
ConvertPIXELSToTWIPS lngLeft, lngTop
ConvertPIXELSToTWIPS lngWidth, lngHeight
DoCmd.SelectObject acReport, rpt.Name, False
DoCmd.Restore
DoCmd.MoveSize lngLeft, lngTop, lngWidth, lngHeight
End With
'now use Terry's code here
Call MaximizeRestoredReport(rpt)
End Sub
Sub ConvertPIXELSToTWIPS(x As Long, Y As Long)
'From the KB
Dim hDC As Long, hwnd As Long, RetVal As Long
Dim XPIXELSPERINCH, YPIXELSPERINCH
Const LOGPIXELSX = 88
Const LOGPIXELSY = 90
hDC = apiGetDC(0)
XPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSY)
RetVal = apiReleaseDC(0, hDC)
x = (x / XPIXELSPERINCH) * TWIPSPERINCH
Y = (Y / YPIXELSPERINCH) * TWIPSPERINCH
End Sub |
Partager