Visit Gigasoft's Web Site
ProEssentials v8 Help

Chapter 3: ActiveX Printing

 

You can print ProEssentials based images either via simple function calls or via low level API calls.

 

Simple Printing with Dialog Intervention:

PELaunchPrintDialog(bFullPage As Boolean, nWidth As Integer, nHeight As Integer)

 

Parameter

Description

bFullPage

True = print full page, False = use nWidth/nHeight.

nWidth

Width in 1/100th millimeters.

nHeight

Height in 1/100th millimeters.

 

This function invokes a dialog so user can select a printer to print the current image. If bFullPage is FALSE, then the image is sized with nWidth and nHeight and centered on the page.

 

PrintStyleControl

This property controls the visibility of radio buttons and the option selected for printing on the print dialog.

Constant

Description

PEPSC_NONE (0)

No control over Viewing Style

PEPSC_CURRENT_STYLE(1)

Current Viewing Style

PEPSC_DEFAULT_MONO(2)

Switch to Mono Viewing Style

 

DefOrientation

This property controls the default orientation of the printer paper when printing a ProEssentials object. Possible values are as follows:

Constant

Description

PEDO_DRIVERDEFAULT(0)

Use the printer driver

PEDO_LANDSCAPE(1)

Landscape orientation.

PEDO_PORTRAIT(2)

Portrait orientation.

 

PrintDpi

Controls the target resolution in DotsPerInch when printing. If set to Zero, graphic commands are sent directly to the printer:

Value

Description

0

If zero, the chart's image is sent to the printer via the actual graphic primitives and final resolution is based upon the printer's driver settings. This produces the sharpest graphics and may be the best setting when printing with ViewingStyle set to MonoChrome, BitmapGradientMode = False

100
---
600

If non zero, the chart image is prepared as a bitmap (at the specified PrintDpi) and this bitmap is sent to the printer. The default and recommend setting is 300. 300 produces a good looking image while not requiring a huge amount of memory to be sent to the printer.

 

HidePrintDpi

This property controls the visibility of the above PrintDpi end-user setting shown within the ProEssentials built-in print dialog:

Value

Description

TRUE

The End-User can not adjust the PrintDpi setting.

FALSE

The End-User can adjust the PrintDpi setting.

 

 

 

 

Simple Printing without Dialog Intervention:

PEprintgraph(nWidth As Long, nHeight As Long, nOrient As Integer)

 

Parameter

Description

nWidth

Width in 1/100th millimeters.

nHeight

Height in 1/100th millimeters.

nOrient

0=Driver Default, 1=Landscape, 2=Portrait.

 

This function prints the objects image to the operating systems default printer.  If nWidth and nHeight are both zero, the image will print full page.

 

 

Lower Level Printing:

 

The following examples show how to place multiple images on a page.  You can also add other graphics and text as needed providing full control over the printed page.

 

The recommended method uses PEprintgraphEx which is a new feature to simplify printing:

PEprintgraphEx(nDC As Long, nWidth As Long, nHeight As Long, nOriginX As Long, nOriginY As Long)

 

Parameter

Description

nDC

Handle to target device context.

nWidth

Width in 1/100th millimeters.

nHeight

Height in 1/100th millimeters.

nOriginX

Top-Left horizontal location in 1/100th millimeters.

nOriginY

Top-Left vertical location in 1/100th millimeters.

 

This function sends GDI or GDIPLUS commands to the target device context (hDC) to place the object's image within the printer's page at the size and position specified. The current state of PrintDpi and PrintTechnology properties will control which system calls are used to transfer the image.

 

 

The following code can also be found in a VB6 example project accessed via start menu...

Start / All Programs / ProEssentials v8 / VB6 Printing Example Project

 

'**********************************************************************

'** Method of printing using PEprintgraphEx.

'** Assume two controls, Pego1 and Pe3do1 are to be printed

'** on one page with other text or graphics.

'**********************************************************************

 

'// If image is monochrome, BitmapGradientMode = False, then
'// setting PrintDpi = 0 may be preferred.
'// Optionally use or comment out this section
Printer.ScaleMode = vbInches
Dim fInchesX As Single
Dim fInchesY As Single
fInchesX = Printer.ScaleWidth
fInchesY = Printer.ScaleHeight
Printer.ScaleMode = vbPixels
Dim fPixelsX As Single
Dim fPixelsY As Single
fPixelsX = Printer.ScaleWidth
fPixelsY = Printer.ScaleHeight
Dim nDpiX As Integer
Dim nDpiY As Integer
nDpiX = fPixelsX / fInchesX
nDpiY = fPixelsY / fInchesY
Pego1.PrintDpi = 0
Pe3do1.PrintDpi = 0
Pego1.DpiX = nDpiX '// Setting Dpi makes for consistent font sizes between
Pego1.DpiY = nDpiY '// different printers.
Pe3do1.DpiX = nDpiX
Pe3do1.DpiY = nDpiY

'// change to monochome mode //
Pego1.ViewingStyle = PEVS_MONO
Pe3do1.ViewingStyle = PEVS_MONO

Dim hRes As Long
Dim vRes As Long
Dim nOrgX As Long
Dim nOrgY As Long
Dim nExtX As Long
Dim nExtY As Long


Printer.Orientation = 1


'** get size of page, ProEssentials want units of 1/100th millimeter **'
Printer.ScaleMode = vbMillimeters
vRes = Printer.ScaleHeight * 100
hRes = Printer.ScaleWidth * 100


'// Print something so VB knows something was sent to printer //
Printer.Print " "


'// first image //'
nOrgX = 0
nOrgY = 0
nExtX = hRes * 0.5
nExtY = vRes * 0.5
Call Pego1.PEprintgraphEx(Printer.hDC, nExtX, nExtY, nOrgX, nOrgY)


'// second image //
nOrgX = hRes * 0.5
nOrgY = vRes * 0.5
nExtX = hRes * 0.5
nExtY = vRes * 0.5
Call Pe3do1.PEprintgraphEx(Printer.hDC, nExtX, nExtY, nOrgX, nOrgY)


Printer.EndDoc


'// Reset to color mode //
Pego1.ViewingStyle = PEVS_COLOR
Pe3do1.ViewingStyle = PEVS_COLOR


Pego1.PEactions = REINITIALIZE_RESETIMAGE
Pe3do1.PEactions = REINITIALIZE_RESETIMAGE

 

 

'**********************************************************************

'** Lowest level approach to printing, playing metafile.

'** Above code does the same thing for you when

'** PrintDpi = 0

'**********************************************************************

 

Dim hMeta, hRes, vRes, OldMM, lresult As Long

Dim nOrgX, nOrgY, nExtX, nExtY, hRgn As Long

Dim pt As POINTSTRUCT ' defined in "PE5API.BAS"

 

'** send printer something so VB knows to start page **'

Printer.Print " "

 

'** get size of page **'

Printer.ScaleMode = 3 ' pixels

hRes = Printer.ScaleWidth

vRes = Printer.ScaleHeight

 

'** set mapping mode MM_TEXT **'

oldMM = SetMapMode(Printer.hdc, 1)

 

'// first image //

'** Set viewport org and extents **'

nOrgX = hRes * 0

nOrgY = vRes * 0

nExtX = hRes * 0.5

nExtY = vRes * 0.5

lresult = SetViewportOrgEx(Printer.hdc, nOrgX, nOrgY, pt)

lresult = SetViewportExtEx(Printer.hdc, nExtX, nExtY, pt)

 

'** Create Clipping Region **'

hRgn = CreateRectRgn(nOrgX, nOrgY, nExtX + nOrgX, nExtY + nOrgY)

lresult = SelectClipRgn(Printer.hdc, hRgn)

lresult = DeleteObject(hRgn)

 

'** reset image shape to match shape defined by SetViewportExt **'

Pego1.PEresetimageEx nExtX, nExtY, nOrgX, nOrgY

hMeta = Pego1.PEgetmeta

lresult = PEplaymetafile(Pego1, Printer.hdc, hMeta)

 

'// second image //

'** Set viewport org and extents **'

nOrgX = hRes * 0.5

nOrgY = vRes * 0.5

nExtX = hRes * 0.5

nExtY = vRes * 0.5

lresult = SetViewportOrgEx(Printer.hdc, nOrgX, nOrgY, pt)

lresult = SetViewportExtEx(Printer.hdc, nExtX, nExtY, pt)

 

'** Create Clipping Region **'

hRgn = CreateRectRgn(nOrgX, nOrgY, nExtX + nOrgX, nExtY + nOrgY)

lresult = SelectClipRgn(Printer.hdc, hRgn)

lresult = DeleteObject(hRgn)

 

'** reset image shape to match shape defined by SetViewportExt **'

Pe3do1.PEresetimageEx nExtX, nExtY, nOrgX, nOrgY

hMeta = Pe3do1.PEgetmeta

lresult = PEplaymetafile(Pe3do1, Printer.hdc, hMeta)

Printer.EndDoc

 

' ** reset mapping mode **'

lresult = SetMapMode(Printer.hdc, oldMM)

 

' ** reset image to current aspect ratio **'

Pego1.PEresetimage 0, 0

Pe3do1.PEresetimage 0, 0

 

An important tip regarding low level printing and working with text and graphic mapping modes.   It's best to first do a SaveDC Windows API call, output either your graphics or text, perform a RestoreDC call, output other graphics and or text, followed by a RestoreDC when completed with the DC. If you seem to not be able to gain control of your printing logic, doing a SaveDC and RestoreDC Windows API call may resolve your issues.