The MASM Forum

Miscellaneous => The Orphanage => Topic started by: shankle on November 27, 2012, 08:18:35 AM

Title: printing a bitmap
Post by: shankle on November 27, 2012, 08:18:35 AM
If you test this, the printer will need to be turned on.
Having a lot of trouble getting a bitmap to print on the printer.
I have been able to get a bitmap shown on the screen.
I have looked at R. Thomas's  showdib program and frankly dibs
are a complete mystery to me. Anyway the program doesn't do
what I want to do. All the goodies are zipped and attached here.
The tloadimage program is already compiled but you can do it
again with the included ".bat" file.
I am especially having trouble with the "LoadImage API".
According to what I have read the "LoadBitMap API" will not
write to a printer. Anyway the LoadImage failed.
 
Title: Re: printing a bitmap
Post by: qWord on November 27, 2012, 08:39:30 AM
LoadImage needs the handle of the Module (hInstance) that contains the Bitmap-resource.
Title: Re: printing a bitmap
Post by: shankle on November 28, 2012, 12:02:26 AM
Thank you qWord.
Loadimage shows no error now.
Getobject shows no errors.
SelectObject shows no errors.
Bitblt is showing an error.
I suspect the fields in bmpdc are invalid.
Title: Re: printing a bitmap
Post by: dedndave on November 28, 2012, 12:14:24 AM
hello Jack

during WM_CREATE, you create a compatible DC with 0 as the parm
it must have an hDC
(the reason BitBlt is failing is the source hDC is 0 because it returns an error)

then, you must select the loaded bitmap handle into the compatible DC

if you want, you can use the desktop hDC as a reference

invoke  GetDC,HWND_DESKTOP
mov     hdcDesktop,eax
invoke  CreateCompatibleDC,eax
mov     hdcMem,eax
invoke  ReleaseDC,HWND_DESKTOP,hdcDesktop


now, you can select the bitmap handle into hdcMem
invoke  SelectObject,hdcMem,hBitmap
mov     hbmpMem,eax                   ;save the original and restore it before deleting the DC


you may not need to use the desktop DC - you might be able to use the printer DC
i have never tried that   :P
Title: Re: printing a bitmap
Post by: shankle on November 28, 2012, 01:40:21 AM
Hi Dave,
I just found out that 2 API's will not work when trying to print a bitmap.
  LoadBitMap and BitBlt.
I must go the DIB route using Stretchdibits and God knows what else.
Nothing is ever easy.....
Title: Re: printing a bitmap
Post by: dedndave on November 28, 2012, 03:52:46 AM
that's right - i remember reading that you have to use LoadImage with LR_CREATEDIBSECTION
Title: Re: printing a bitmap
Post by: shankle on November 30, 2012, 01:37:51 AM
Gave up on printing bitmaps.
Will find another way to skin the cat. Might not give
me all I need but better than the DIB mess.

As a side, R. Thomas's "showdib" program printed a bitmap
just fine. For some reason I deleted the "showdib.exe" file
and recompiled the program in Windows 7 pro 64-bit using
masm32. Guess what, the program no longer works. I think
it has something to do with the API upgrades from when Mr.
Thomas wrote the program and now.