I think I've found a better way using GetDeviceCaps():
- Private Declare Function GetDeviceCaps Lib "gdi32" _
-
(ByVal hdc As Long, ByVal nIndex As Long) As Long
-
-
Private Const LOGPIXELSX = 88
-
Private Const LOGPIXELSY = 90
-
-
Private Sub Command1_Click()
-
Dim dpiX As Long, dpiY As Long
-
dpiX = GetDeviceCaps(Printer.hdc, LOGPIXELSX)
-
dpiY = GetDeviceCaps(Printer.hdc, LOGPIXELSY)
-
-
MsgBox (dpiX & " " & dpiY)
-
End Sub
I
think this is working - if you can confirm/deny it's validity, please tell me.
Now that I (hopefully) have the printer resolution, how do I use that to put something on paper at, say, X = 2 inches, Y = 4 inches? I've been using this code to scale/position the image:
- Sub SetLargePrinterScale(obj As Object, VertPosition As Single)
-
Dim Owid As Single
-
Dim Ohgt As Single
-
Dim Pwid As Single
-
Dim Phgt As Single
-
Dim Xmid As Single
-
Dim Ymid As Single
-
Dim S As Single
-
Dim ScaleFactor As Single
-
-
ScaleFactor = (50 - frmPrint.Slider3.Value) / 10
-
-
Owid = obj.ScaleX(obj.ScaleWidth, obj.ScaleMode, vbPixels)
-
Ohgt = obj.ScaleY(obj.ScaleHeight, obj.ScaleMode, vbPixels)
-
-
Pwid = Printer.ScaleX(Printer.ScaleWidth, Printer.ScaleMode, vbPixels)
-
Phgt = Printer.ScaleY(Printer.ScaleHeight, Printer.ScaleMode, vbPixels)
-
-
If Ohgt / Owid > Phgt / Pwid Then
-
S = Phgt / Ohgt
-
Else
-
S = Pwid / Owid
-
End If
-
-
Pwid = obj.ScaleX(Pwid * ScaleFactor, vbPixels, obj.ScaleMode) / S
-
Phgt = obj.ScaleY(Phgt * ScaleFactor, vbPixels, obj.ScaleMode) / S
-
-
Xmid = (obj.ScaleLeft + obj.ScaleWidth / 2) * ScaleFactor
-
Ymid = (obj.ScaleTop + obj.ScaleHeight / 1.6) * ScaleFactor
-
-
-
Printer.Scale (Xmid - Pwid / 2, Ymid - Phgt / 2)-(Xmid + Pwid / 2, Ymid + Phgt / 2)
-
-
End Sub
It prints the output in the middle of the page (X and Y). To move the printout away from the center, I've been adding an integer to the Xmid and Ymid equations:
Xmid = (obj.ScaleLeft + obj.ScaleWidth / 2) * ScaleFactor
+ 100
Ymid = (obj.ScaleTop + obj.ScaleHeight / 1.6) * ScaleFactor
+ 200
but for portability I need to take the current printer resolution into account.
Any suggestions?
joe