Solved

StretchBlt in VB3 on Win 95

Posted on 1997-06-12
5
446 Views
Last Modified: 2008-03-03
Wow! What a time I'm having with StretchBlt.
I need to print a BMP to the printer along with text and drawing objects on the same page.
I have the code of an old demo program called BMPKIT.MAK which performs this using StretchBlt API call when run in Win 3.x but not when run on a 95 machine. It uses StretchBlt successfully to the screen but not ot the printer.
I have to produce an application which will run on both systems because users have both.

Any Ideas ?

PS Even when loaded in VB4 32bit . StretchBlt returns True but nothing
comes out the printer even though the Declares have been changed to the 32
bit library versions.
???????????????????????????????????????????????          :(
0
Comment
Question by:watin
[X]
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
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:tward
ID: 1427180
It might help if you post the code you are using to do it.  I am familiar with StretchBLT and printing.

0
 

Author Comment

by:watin
ID: 1427181
Code used as Requested
Definition
Global scalex As Single
Global scaley As Single

'* Declarations for the GDI functions...place in Global Module.
Declare Function CreateCompatibleDC% Lib "GDI" (ByVal hdc%)
Declare Function SelectObject% Lib "GDI" (ByVal hdc%, ByVal hObject%)
Declare Function DeleteDC% Lib "GDI" (ByVal hdc%)
Declare Function Escape Lib "GDI" (ByVal hdc As Integer, ByVal nEscape As Integer, ByVal nCount As Integer, lplnData As Any, lpOutData As Any) As Integer

Declare Function StretchBlt% Lib "GDI" (ByVal hdc%, ByVal x%, ByVal y%, ByVal nWidth%, ByVal nHght%, ByVal hSrcDC%, ByVal xSrc%, ByVal ySrc%, ByVal nSrcWidth%, ByVal nSrcHeight%, ByVal dwRop&)
Declare Function StretchBltP Lib "c:\windows\system\Gdi32.dll" Alias "StretchBlt" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long


Activating code
Sub Command3_Click ()
'these are difinde in order to try calling the GDI32 version of the
'call which requires LONGs. it didn't work.
Dim src, ApiError, printgraphicx, hMemoryDC, prhdc As Long
Dim hOldBitMap, printgraphicy As Long

'* Print all items other than the image first.

printer.ScaleMode = 5

printer.CurrentX = 3
printer.CurrentY = 3
printer.Print "Hello"

printer.CurrentY = 4
printer.CurrentX = 1
printer.DrawWidth = 5
printer.Line -Step(printer.CurrentX + 2, 0)

'*After printing all other elements include your BMP
'printing routine, as below.


'* Print Scaled Image

'*Make certain we have valid scaling values
If scalex = 0 Then scalex = 1
If scaley = 0 Then scaley = 1

'*Set GDI Constants
Const NULL = 0&
Const SRCCOPY = &HCC0020
Const NEWFRAME = 1
Const pixel = 3


'* StretchBlt requires pixel coordinates.

picture1.ScaleMode = pixel
printer.ScaleMode = pixel

'*First two variables are the x,y coordinates (in Pixels)
'for the placement of images on the printed page. Since the
'form's ScaleMode is 5 for inches, multiply by 300 to
'match the the current inch positions of Picture2 on
'the 300 DPI device.

'*Second pair of variables set the height and width of the
'graphic to match the pixel size of the original picture
'in the invisible Picture1 box.

printgraphicx = Picture2.Left * 300
printgraphicy = Picture2.Top * 300

printer.ScaleWidth = picture1.ScaleWidth * scalex
printer.ScaleHeight = picture1.ScaleHeight * scaley

'*Do not change the order of these statements.

hMemoryDC = CreateCompatibleDC(picture1.hDC)
hOldBitMap = SelectObject(hMemoryDC, picture1.Picture)
   
'Variables for the StretchBlt function:
'1. Source of image HMemeoryDC -- set above from original picture
'2,3. Positioning on output object. Must be integer, in pixels.
'4,5. Width, height of output image. Here we use the values set above.
'6, Source of image...in this case the memory image set by CreateCompatibleDC function
'7,8. Don't know. Set to 0 works just fine! Experiment and let me know.
'9,10. X/Y coordinates for how much of original to put in new object. You can use
'these values for cropping, if you like.
'11. SRCCOPY, as set in constants above. Change at own risk.
prhdc = printer.hDC
src = SRCCOPY
ApiError = StretchBlt(prhdc, printgraphicx, printgraphicy, printer.ScaleWidth, printer.ScaleHeight, hMemoryDC, 0, 0, picture1.ScaleWidth, picture1.ScaleHeight, src)
MsgBox "Printing StretchBlt returned " & Format$(ApiError, "True/False")
   
   'this is the 32bit call but it didn't work
   'Declare Function StretchBlt Lib "gdi32" Alias "StretchBlt" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
hOldBitMap = SelectObject(hMemoryDC, hOldBitMap)
ApiError = DeleteDC(hMemoryDC)

'*Send image and text to printer

printer.NewPage
printer.EndDoc
End Sub

0
 
LVL 7

Expert Comment

by:tward
ID: 1427182
This may or may not help but where are your defines for the 32 bit version of CreateCompatableDC and SelectObject and the other functions that go along with StretchBLT?
0
 
LVL 2

Accepted Solution

by:
weekee earned 200 total points
ID: 1427183
Actually, if you are using Visual Basic 4, there is a method known as paintpicture. It works so sort like StretchBlt. The details of all the parameters used can be found in the help file.
The advantage is that you need not need to do all those API declaration. I have tried to use the method to send to the printer.hdc and everything works fine. If you familar with StretchBlt, you will have no problems with the parameters for the paintpicture method becasue both are similar
0
 

Author Comment

by:watin
ID: 1427184
Thanks weekee & tward for your suggestions but I have found the problem and solved it.
I am not using VB4 because the same application compiled in vb4 takes 3 disks to distribute and in vb3 takes only 2/3 of one.
Also it takes longer to execute when run in vb4.

Anyway stretchblt now works
The problem was that my printer driver was slightly incompatible with the printer and although it worked well to all appearances it must not have given the right answers to stretchblt and wouldn't work. That's all folks. The easiest answer is often the one.

Now How do I remove this question so others don't try to answer it for ever ?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 5 hours left to enroll

622 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