Link to home
Start Free TrialLog in
Avatar of watin
watinFlag for Australia

asked on

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.
???????????????????????????????????????????????          :(
Avatar of tward
tward

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

Avatar of watin

ASKER

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

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?
ASKER CERTIFIED SOLUTION
Avatar of weekee
weekee

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of watin

ASKER

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 ?