|
4#
楼主 |
发表于 2015-6-6 08:30:01
|
只看该作者
Private Function GetTwips(intXResolution As Integer, intAxis As Integer)
' Experience has shown that the twips/pixel ratios
' are dependent on the screen resolution. If you find this
' not to be true in your particular case, you'll need to modify
' this routine.
Select Case intXResolution
Case 1024, 1280
GetTwips = IIf(intAxis = glrcXAxis, _
glrcDesignXTwipsHiRes, glrcDesignYTwipsHiRes)
Case 640, 800
GetTwips = IIf(intAxis = glrcXAxis, _
glrcDesignXTwipsLoRes, glrcDesignYTwipsLoRes)
Case Else
' If the value is invalid, just assume the designed used
' a high-res screen. The worst this can do is cause
' an image that's a little small.
GetTwips = IIf(intAxis = glrcXAxis, _
glrcDesignXTwipsHiRes, glrcDesignYTwipsHiRes)
End Select
End Function
Function glrResizeForm(frm As Form, ByVal fDoResize As Variant, rctOriginal
As glrTypeRect)
' Called from the Resize event of forms.
' Attempt to resize the form and all its
' controls. Don't do anything if the
' current height of the form is 0, or if it's iconic.
' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.
' In:
' frm: A reference to the form in question
' fDoResize: Yes/No (Actually do the resize, or just track the
information?)
' rctOriginal: the original coordinates
' Out:
' Nothing
Dim rctNew As glrTypeRect
Dim rctClient As glrTypeRect
Dim varTemp As Variant
Dim intWidth As Integer
Dim intHeight As Integer
Dim sglFactorX As Single
Dim sglFactorY As Single
On Error GoTo glrResizeWindowError
' Make sure the user hasn't sized this thing down
' to the nubs. If the client area is 0 height,
' it's time to call it quits.
glr_apiGetClientRect frm.hwnd, rctNew
intHeight = (rctNew.Y2 - rctNew.Y1)
If intHeight = 0 Or glr_apiIsIconic(frm.hwnd) Then
Exit Function
End If
' Get the current width. Already found the
' current height.
intWidth = (rctNew.X2 - rctNew.X1)
' Calc the scaling factor, given the current
' height/width and the previous height/width.
' Could be that rctOriginal has not yet been
' initialized, so trap for that error.
sglFactorX = intWidth / (rctOriginal.X2 - rctOriginal.X1)
sglFactorY = intHeight / (rctOriginal.Y2 - rctOriginal.Y1)
sglFactorOK:
' Store away the current values for
' the next time through here.
With rctOriginal
.X1 = rctNew.X1
.X2 = rctNew.X2
.Y1 = rctNew.Y1
.Y2 = rctNew.Y2
End With
' If the ratios are 1, there's nothing to do.
If (sglFactorX <> 1) Or (sglFactorY <> 1) Then
' If you actually want to do some resizing, do it now.
If fDoResize Then
SetFormSize frm, sglFactorX, sglFactorY, rctNew, False
End If
End If
glrResizeWindowExit:
Exit Function
glrResizeWindowError:
If Err = glrcErrDivisionByZero Then
sglFactorX = 1
sglFactorY = 1
Resume sglFactorOK
Else
HandleError "glrResizeForm", Err.Number, Err.Description
Resume Next
End If
End Function
Function glrScaleForm(frm As Form, intX As Integer, intY As Integer,
rctOriginal As glrTypeRect)
' Called from the Open event of forms.
' Attempts to scale the form appropriately
' for the given screen size, as compared
' to the size screen on which it was designed.
' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.
'
' In:
' frm: A reference to the form in question
' intX: the horizontal screen resolution at which the form was
designed.
' intY: the vertical screen resolution at which the form was
designed.
' rctOriginal: original coordinates
'
' Out:
' Nothing
' Comments:
' Use a function call like this:
' intRetval = glrScaleForm(Me, 640, 480, rctOriginal)
' to autoscale a form created at 640x480 resolution.
Dim intTwipsPerPixelX As Integer
Dim intTwipsPerPixelY As Integer
Dim intScreenX As Integer
Dim intScreenY As Integer
Dim sglFactorX As Single
Dim sglFactorY As Single
GetScreenScale intX, intY, sglFactorX, sglFactorY
' Whether or not this form gets rescaled,
' you'll need to store away the current size
' for later. The reason you must call GetFormSize
' here, rather than glr_apiGetClientRect, is that
' you need the screen positioning information
' which you don't get with GetClientRect.
GetFormSize frm, rctOriginal
' If the x and y factors are both 1, there's nothing
' to do, so get out here.
If (sglFactorX = 1) And (sglFactorY = 1) Then Exit Function
' If you don't want forms to expand (they were created on a
' lower-resolution device than the current device), but only
' shrink (they were created on a higher-resolution device
' than the current device), then uncomment the next line.
'If (sglFactorX > 1) And (sglFactorY > 1) Then Exit Sub
DoCmd.RepaintObject
SetFormSize frm, sglFactorX, sglFactorY, rctOriginal, True
End Function
Private Sub HandleError(strFunction As String, intErr As Integer, strError
As String)
MsgBox "Error: " & strError & " (" & intErr & ")", vbExclamation,
strFunction
End Sub |
|