Custom Print Preview window for VB5

Posted on 1998-10-01
Last Modified: 2010-04-30

Create a VB5 form which functions as a custom Print Preview window.


(1) No external 3rd-party software may be involved; use only VB5 internals.

(2) Print Preview window (PPWin) will be called from a custom VB5 app.

(3) Win32 API calls are welcome, if well documented.

(4) User must be able to print PPWin contents with full WYSIWYG results.

(5) PPWin must be able to display bitmap (.BMP) files.

   o .BMP file path to be passed to PPWin programmatically.

   o Size of .BMP file in PPWin is flexible--will be determined programmatically.

(6) PPWin must be able to accept and display text strings programmatically

   These 1-3 line titles will label and describe the .BMP image, and will be determined internally by the developer.

(6) While PPWin is displayed, user must be able to:

   o Change portrait/landscape options. PPWin contents change accordingly.

         If image is more suited to landscape, then image will expand when "Landscape" is selected. Reverse is true for portrait layouts.

   o Submit the data to the printer of his/her choice.


If this can be accomplished with a Form and a PictureBox control, that's fine--but it MUST be WYSIWYG, it MUST reflect what will be produced on the printer. Also, the
ability to scale items in this Print Preview window in ad hoc fashion is crucial.

The answer doesn't have to be a polished procedure. But it does need to be past the conceptual level and down to real code examples.

This is a big question, I know, and I'm giving it all the point I've got. I'll add more as I earn them!


Question by:bryker
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 14

Expert Comment

ID: 1437698

go to my web site :

You will find a complete Print Preview OCX. As it is a shareware (only 20$), it does all you want.

I know it is a 3dr party, but if you don't want to register, send me a mail with specific things you would like to know.


Author Comment

ID: 1437699

This procedure may be folded into an app distributed to various countries in the Pacific Rim. We've learned long ago not to use any 3rd-party software that's not absolutely essential.

The legalities almost inevitably come back upon us somehow. Plus, we need source code which can be tailored per client.

Again, please, folks, no 3rd-party software. Just good old VB5 code.

Author Comment

ID: 1437700
Adjusted points to 190
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

LVL 14

Expert Comment

ID: 1437701
Why don't you take a look to this OCX, as I told you, I can help you for some parts.

Author Comment

ID: 1437702

If you would like to submit CODE with which this can be accomplished, I don't care what OCX from which it is sourced or modeled.

I have no doubts that this OCX works perfectly and does everything I seek--it remains, however, a 3rd party product.

If you want to submit some code, be my guest.  Otherwise, let's give others a chance to submit some actual code examples.

Thanks for your cooperation and helpfulness.

Author Comment

ID: 1437703
Adjusted points to 200
LVL 14

Expert Comment

ID: 1437704
What I would like to say, is that I could help you by submiting some code, but I need to know exactly what you want, and to have idea, is just taking a look to the Print Preview OCX (not use it, nor buy it)

Author Comment

ID: 1437705
So the question is, what do I want in a Print Preview window?

To rehash my section SPECIFICS in my initial question:

   o User must be able to easily switch between Portrait/Landscape;

   o PPWin must accept .BMP images submitted programmatically;

   o Images placed on the PPWin must be sizeable, and able to
be "maximized" to take advantage of available space, depending
on Portrait/Landscape settings;

   o Developer must be able to programmatically place text into the PPWin;

   o Print results from PPWin must be WYSIWYG;

LVL 14

Accepted Solution

waty earned 200 total points
ID: 1437706
First of all, you have to deal with a picture to preview

All the following text was taken from my Print Preview OCX.

o User must be able to easily switch between Portrait/Landscape
Set the picture size to Printer.Width, Printer.Height. If the user change from Portrait to Landscape, change the picture size according to new Printer.Width and Printer.Height.

o PPWin must accept .BMP images submitted programmatically
Here is my code to preview a bitmap
frmPreview.PictList = LoadPicture(previewLine.sText)

' *** Paint the bitmap
frmPreview.pictPreview(0).PaintPicture frmPreview.PictList, previewLine.nCurrentX, previewLine.nCurrentY
Set frmPreview.PictList = Nothing

Here is the code to print the bitmap :

' *** Load the bitmap ***
frmPreview.PictList = LoadPicture(previewLine.sText)

' *** Print the bitmap
PrintBitmap frmPreview.PictList, previewLine.nCurrentX, previewLine.nCurrentY
Set frmPreview.PictList = Nothing

Public Sub PrintBitmap(pictBox As PictureBox, nX As Integer, nY As Integer)
   ' *** Print a bitmap
   Printer.PaintPicture pictBox, nX, nY
End Sub

o Images placed on the PPWin must be sizeable, and able to
be "maximized" to take advantage of available space, depending
on Portrait/Landscape settings;

Private Sub Stretch(Src As Control, Dest As Control, StretchMode As Long)
   ' *** Stretch pictures ***
   Dim nHoldSrcMode     As Long
   Dim nHoldDestMode    As Long
   Dim XSrc             As Long
   Dim YSrc             As Long
   Dim XDest            As Long
   Dim YDest            As Long
   Dim nSrcWidth        As Long
   Dim nSrcHeight       As Long
   Dim nDestWidth       As Long
   Dim nDestHeight      As Long
   Dim hSrcDC           As Long
   Dim hDestDC          As Long
   Dim nRet             As Long
   Const SRCCOPY = &HCC0020
   On Error Resume Next
   nHoldSrcMode = Src.ScaleMode
   nHoldDestMode = Dest.ScaleMode
   Src.ScaleMode = 3
   Dest.ScaleMode = 3
   XSrc = 0
   YSrc = 0
   nSrcWidth = Src.ScaleWidth
   nSrcHeight = Src.ScaleHeight
   XDest = 0
   YDest = 0
   nDestWidth = Dest.ScaleWidth
   nDestHeight = Dest.ScaleHeight
   hSrcDC = Src.hdc
   hDestDC = Dest.hdc
   nRet = SetStretchBltMode(hDestDC, StretchMode)
   nRet = StretchBlt(hDestDC, XDest, YDest, nDestWidth, nDestHeight, hSrcDC, XSrc, YSrc, nSrcWidth, nSrcHeight, SRCCOPY)
   Src.ScaleMode = nHoldSrcMode
   Dest.ScaleMode = nHoldDestMode
End Sub

o Developer must be able to programmatically place text into the PPWin;
With frmPreview.pictPreview(0)
  If previewLine.nTextRotation = 0 Then
     ' *** set the font ***
     .FontName = Trim(previewLine.sFontName)
     .FontSize = previewLine.dFontSize
     .FontBold = previewLine.bFontBold
     .FontUnderline = previewLine.bFontUnderline
     .FontItalic = previewLine.bFontItalic
     .FontStrikethru = previewLine.bFontStrikeThru
     If (previewLine.nCount <> nRowFind) Then
        .ForeColor = previewLine.nForeColor
        .ForeColor = &HC0&
     End If
     Call SetBkColor(frmPreview.pictPreview(0).hdc, previewLine.nBackColor)
     ' *** set the position ***
     .CurrentX = previewLine.nCurrentX
     .CurrentY = previewLine.nCurrentY
     ' *** print the text ***
     frmPreview.pictPreview(0).Print previewLine.sText
End With

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question