Using PreviewPicture

Using PreviewPicture

Post by daniel.smi » Fri, 11 Jul 2003 18:42:20


Hi Folks,
Is there a way of getting hold of the preview picture of a Visio
Document?

I've looked at one or two ways, there is a PreviewPicture property of
a Visio.document which is a stdole.IPictureDisp type. I didn't seem to
be able to use this though.

A long-winded way would be to convert a VSD file into a VDX file and
then extract the PreviewPicture element. The resulting Hex would then
have to be converted to binary and then saved as a .gif file. But
surely this laborious process would be unnecessary if the
PreviewPicture property could be made to work?

The reason for this question, is that on the project I'm working on we
are displaying pictures of Visio Documents. These previews are
currently .gif files where we have exported the VSD into .gif format
and then constrained the image within a PictureBox on a VB.NET form.
Whilst this works it would be interesting to see if we could use the
PreviewPicture and it should have a nice knock-on effect of being much
smaller in size.

Advice and ideas more than welcome.

Best Regards,

Daniel Smith
 
 
 

Using PreviewPicture

Post by Mai-lan [M » Wed, 16 Jul 2003 13:15:54

i, there: Here's a code sample in a VB form that does print preview. I've
copied it with all the form data so you can get a sense of what's on it.
Sorry that the formatting is a little messed up.

VERSION 5.00

Begin VB.Form frmPrintPreview

Caption = "Print Preview"

ClientHeight = 4185

ClientLeft = 60

ClientTop = 360

ClientWidth = 4680

LinkTopic = "Form1"

ScaleHeight = 4185

ScaleWidth = 4680

StartUpPosition = 3 'Windows Default

Begin VB.PictureBox pctPreview

BorderStyle = 0 'None

Height = 3360

Left = 105

ScaleHeight = 3360

ScaleWidth = 4395

TabIndex = 2

Top = 135

Width = 4395

Begin VB.Label lblNoMetafile

Alignment = 2 'Center

Caption = "No Preview is Available"

BeginProperty Font

Name = "MS Sans Serif"

Size = 18

Charset = 0

Weight = 700

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

Height = 1065

Left = 255

TabIndex = 3

Top = 885

Width = 3870

End

End

Begin VB.CommandButton cmdPrint

Caption = "Print"

Height = 420

Left = 1965

TabIndex = 1

Top = 3615

Width = 1215

End

Begin VB.CommandButton cmdCancel

Cancel = -1 'True

Caption = "Cancel"

Height = 420

Left = 3330

TabIndex = 0

Top = 3600

Width = 1215

End

End

Attribute VB_Name = "frmPrintPreview"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

' frmPrintPreview / PrintPreview.bas

' Copyright (c) Microsoft Corporation. All rights reserved.

'<ignore>

Option Explicit

'</ignore>

' This file contains code that creates a print preview form from

' a Visio drawing.

' The document and printer values are saved to use if the user clicks on the

' Print button.

Dim vsoTargetDocument As Visio.Document

Dim strSelectedPrinter As String

' The PlayMetaFile Windows API function is used to place the metafile

' of the Visio page into the picture control on the form.

Private Declare Function PlayMetaFile Lib "gdi32" (ByVal hDC As Long, _

ByVal hMF As Long)

Private Sub cmdCancel_Click()

'

' cmdCancel_Click

'

' Abstract - This procedure is run when the user clicks on the Cancel

' button. The form is hidden.

'

On Error GoTo cmdCancel_Click_Err


Me.Hide


Exit Sub


cmdCancel_Click_Err:

' Display the error

If Not (vsoTargetDocument Is Nothing) Then

If (vsoTargetDocument.Application.AlertResponse = 0) Then

MsgBox Err.Description

Else

Debug.Print Err.Description

End If

Else

Debug.Print Err.Description

End If

End Sub

Private Sub cmdPrint_Click()

'

' cmdPrint_Click

'

' Abstract - This procedure is called when the user clicks on the Print

' button. The document is printed using the Visio Print method.

'

Dim strCurrentActivePrinter As String


On Error GoTo cmdPrint_Click_Err


' Set up the desired printer. Save the current printer

' so that it can be restored when this print process is

' done.

strCurrentActivePrinter = _

vsoTargetDocument.Application.ActivePrinter

If strCurrentActivePrinter <> strSelectedPrinter Then

vsoTargetDocument.Application.ActivePrinter = _

strSelectedPrinter

End If


' Use the Visio print command to print the document.

vsoTargetDocument.Print


' Restore the original active printer.

If strCurrentActivePrinter <&g