?
Solved

Custom Print Preview window for VB5

Posted on 1998-10-01
9
Medium Priority
?
273 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
ID: 1437698
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
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.
0
 

Author Comment

by:bryker
ID: 1437700
Adjusted points to 190
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Expert Comment

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

Author Comment

by:bryker
ID: 1437702
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
ID: 1437703
Adjusted points to 200
0
 
LVL 14

Expert Comment

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

Author Comment

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

0
 
LVL 14

Accepted Solution

by:
waty earned 400 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
     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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

840 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