Author Topic: printing a bitmap  (Read 4021 times)

shankle

  • Member
  • ****
  • Posts: 857
printing a bitmap
« 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.
 

qWord

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: printing a bitmap
« Reply #1 on: November 27, 2012, 08:39:30 AM »
LoadImage needs the handle of the Module (hInstance) that contains the Bitmap-resource.
MREAL macros - when you need floating point arithmetic while assembling!

shankle

  • Member
  • ****
  • Posts: 857
Re: printing a bitmap
« Reply #2 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.

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: printing a bitmap
« Reply #3 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

Code: [Select]
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
Code: [Select]
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

shankle

  • Member
  • ****
  • Posts: 857
Re: printing a bitmap
« Reply #4 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.....

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: printing a bitmap
« Reply #5 on: November 28, 2012, 03:52:46 AM »
that's right - i remember reading that you have to use LoadImage with LR_CREATEDIBSECTION

shankle

  • Member
  • ****
  • Posts: 857
Re: printing a bitmap
« Reply #6 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.