StretchBlt in VB3 on Win 95

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.
???????????????????????????????????????????????          :(
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

watinAuthor Commented:
Code used as Requested
Global scalex As Single
Global scaley As Single

'* Declarations for the GDI 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 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
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

End Sub

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?
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
watinAuthor Commented:
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 ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.