Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to print a tiff image from a custom ActiveX control
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
How to print a tiff image from a custom ActiveX control
Miscellaneous
Thread ID:
00147208
Message ID:
00147208
Views:
84
Dear Christof
I read your reply to Alan regarding how to print the text of RTF control and found it very useful. But I still do not know how to solve my problem yet. I've been trying to print a tiff image stored in a custome ActiveX control, using some of your code, but I still failed. Can you take your time reading the Visual Basic code (which works) and my VFP code to see what else I need to do to print it. Thank you very much.
*********1. Visual Basic Code***************
'In main program (module) declare DLL and some variables
Type RECT 'user-defined variable type
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Public Const HORZRES = 8
Public Const VERTRES = 10

Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long

Public Sub Form_PrintImage(obj As frmMain, imgDirect As Boolean)
Dim rcode As Long
Dim prect As RECT
Dim rows As Integer
Dim cols As Integer
Dim pxSize As Integer
Dim pySize As Integer
Dim desRC As RECT
Dim pd As Long


'Set the number of rows & cols we will be printing
'Use the ROI values
rows = VisImageCtrl1.ROIEndy - VisImageCtrl1.ROISty
cols = VisImageCtrl1.ROIEndx - VisImageCtrl1.ROIStx

'Get the printer resolution in pixels
pxSize = GetDeviceCaps(Printer.hdc, HORZRES)
pySize = GetDeviceCaps(Printer.hdc, VERTRES)

'Setup a destination rectangle in pixel coordinates
desRC.Left = 0
desRC.Top = 0
desRC.Right = pxSize
desRC.Bottom = pySize

'Adjust the aspect ration of the print area to meet the image aspect 'ratio
desRC.Bottom = ((desRC.Right * rows) / cols)
'we failed adjust on height...reset and try to adjust width
If (desRC.Bottom > pySize) Then
desRC.Bottom = pySize
desRC.Right = ((desRC.Bottom * cols) / rows)
' now center the image on the output page
desRC.Left = ((pxSize / 2) - (desRC.Right / 2))
' readjust the right for the new left position
desRC.Right = (desRC.Right + desRC.Left)
'no use trying to correct for aspect ... jsut print 1:1
If (desRC.Right > pxSize) Then
desRC.Left = 0
desRC.Top = 0
desRC.Right = pxSize
desRC.Bottom = pySize
End If
End If

'Initiate a Print Job with the Print Method
Printer.Print

'Display the hourglass mouse pointer.
Screen.MousePointer = 11

'print the image
VisImageCtrl1.PrintStartX = desRC.Left
VisImageCtrl1.PrintStartY = desRC.Top
VisImageCtrl1.PrintWidth = (desRC.Right - desRC.Left)
VisImageCtrl1.PrintHeight = (desRC.Bottom - desRC.Top)
VisImageCtrl1.PrintHDC = Printer.hdc
If (imgDirect = True) Then
' print the image Direct to Print Driver
VisImageCtrl1.PrintImgFast = 1
End If
' print the image using the VisImage Display engine
VisImageCtrl1.PrintImg = 1

'Restore mouse pointer
Screen.MousePointer = 0

'End the Windows Print Job before leaving, forcing page out
Printer.EndDoc
End Sub

********2. My VFPcode*********
local lcPrinter, nhDC
nhDC = 0
lcPrinter = getprinter()

*Declare API functions that control printer
*Declare an API function
DECLARE INTEGER CreateDC IN Win32API;
String @lpszDriver, String @lpszDevice,;
integer @lpszOutput, integer @lpInitData

nhDC = CreateDC('WINSPOOL', lcPrinter, 0,0)

*Set printing area (all assigned values are randomly selected b/c I do *not know how to get printer resolution in pixels (what dll, and the *parameters)
thisform.VisImageCtrl1.PrintStartX = 1
Thisform.VisImageCtrl1.PrintStartY = 1
Thisform.VisImageCtrl1.PrintWidth = 500
Thisform.VisImageCtrl1.PrintHeight = 500
Thisform.VisImageCtrl1.PrintHDC = nhDC
Thisform.VisImageCtrl1.Printimg = 1

messagebox ("done!")
Next
Reply
Map
View

Click here to load this message in the networking platform