ImageMan ActiveX Control Version 8
PrintStart Method
See Also  Example  Send comments on this topic.
SelectPrinter
If True then the control will display a Print Setup dialog prior to starting the print job. If False the system's default printer will be be used.

Glossary Item Box

Description

Used to initiate printing. This method was designed to simplify printing when using ActiveX containers other than Visual Basic. It allows the control to print without having to enumerate through the printers and create a Device Context.

Syntax

Visual Basic
Public Sub PrintStart( _
   ByVal SelectPrinter As Boolean _
) 

Parameters

SelectPrinter
If True then the control will display a Print Setup dialog prior to starting the print job. If False the system's default printer will be be used.

Remarks

After invoking this method the PrnHDC property will contain the Device Context for the print job. You may then use any Windows API functions to print output to that Device Context in addition to the using the PrintImage method.

Example

(Visual Basic)Copy Code
' Declare API functions at the module level

Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type


Declare Function GetClipBox Lib "gdi32" (ByVal hDC As Long, lpRect As RECT) As Long

. . .

Private Sub PrintImageBestFit()

    ' Print an Image at best fit while maintaining aspect ratio

    Dim nPageXMid As Long, nPageYMid As Long
    Dim ImgWidth As Long, ImgHeight As Long
    Dim nWidth As Long, nHeight As Long
    Dim xMag As Double, yMag As Double
    Dim xRes As Integer, yRes As Integer
    Dim rPrinter As RECT
    Dim lRet As Long

    ' Initialize the ImageMan printing mechanism
    ImageControl1.PrintStart False

    lRet = GetClipBox(ImageControl1.PrnHdc, rPrinter)

    ' Get the image resolution - If not specified default to 300 dpi
    If ImageControl1.ImageXRes <> 0 Then
        xRes = ImageControl1.ImageXRes
    Else
        xRes = 300
    End If

    If ImageControl1.ImageYRes <> 0 Then
        yRes = ImageControl1.ImageYRes
    Else
        yRes = 300
    End If

    ' Calculate the Image size in TWIPS

    ImgWidth = ImageControl1.ImageWidth * 1440 / xRes
    ImgHeight = ImageControl1.ImageHeight * 1440 / yRes

    ' Calculate the center of the page
    nPageXMid = (rPrinter.Right - rPrinter.Left) / 2
    nPageYMid = (Abs(rPrinter.Bottom - rPrinter.Top)) / 2

    xMag = (rPrinter.Right - rPrinter.Left) / ImgWidth
    yMag = (Abs(rPrinter.Bottom - rPrinter.Top)) / ImgHeight

    If xMag > yMag Then
        nWidth = ImgWidth * yMag
        nHeight = ImgHeight * yMag
    Else
        nWidth = ImgWidth * xMag
        nHeight = ImgHeight * xMag
    End If

    ' Tell the control where to print the size

    ImageControl1.DstLeft = nPageXMid - nWidth / 2
    ImageControl1.DstTop = nPageYMid - nHeight / 2
    ImageControl1.DstRight = nPageXMid + nWidth / 2
    ImageControl1.DstBottom = nPageYMid + nHeight / 2

    ' Set the Hourglass Cursor, this may take a few seconds
    MousePointer = 11

    ImageControl1.PrintImage

    ImageControl1.PrintEndDoc

    ' Restore the Cursor

    MousePointer = 0

End Sub

See Also

© 2014 Data Techniques Inc. All Rights Reserved.