Solved

Custom Print Preview window for VB5

Posted on 1998-10-01
9
242 Views
Last Modified: 2010-04-30
GOAL/OVERVIEW:

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


SPECIFICS:

(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.

      
COMMENTS:

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!

Thanks

Breck
0
Comment
Question by:bryker
  • 5
  • 4
9 Comments
 
LVL 14

Expert Comment

by:waty
Comment Utility
Hi,

go to my web site :
    http://www.geocities.com/ResearchTriangle/6311/

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.


0
 

Author Comment

by:bryker
Comment Utility

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.
0
 

Author Comment

by:bryker
Comment Utility
Adjusted points to 190
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
Why don't you take a look to this OCX, as I told you, I can help you for some parts.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:bryker
Comment Utility
waty:

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.
0
 

Author Comment

by:bryker
Comment Utility
Adjusted points to 200
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
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)
0
 

Author Comment

by:bryker
Comment Utility
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;

0
 
LVL 14

Accepted Solution

by:
waty earned 200 total points
Comment Utility
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
     Else
        .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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now