Hi there. To print a bitmap I do the following: 1) create the bitmap and get a handle to its device context 2) PrintDlg(...) with PD_RETURNDC and PD_RETURNDEFAULT to get a handle to the default printer device context (the received handle is not null) 3) StartDoc(...) and StartPage(...) 4) GetDeviceCaps(...) to get the printable area 5) BitBlt(...) to copy data from the device context of the bitmap to the device context of the printer 6) EndPage(...) and EndDoc(...) but this causes a *blank page* to get off the printer. In a previous experiment the code worked, the only difference being that the handle to the device context of the printer was obtained with CreateDC() instead of PringDlg(). I am confused. Can you show me the way to solve this problem ? Many thanks from Alvise.
Posted on 2001-03-30 06:41:00 by alvise
Do we assume you are getting the hDC from the PRINTDIALOG structure?
Posted on 2001-03-30 14:10:00 by tank
Yes. I get the handle to the device context of the printer from the hDC member of PRINTDLG structure. Please notice that when I call PrintDlg() this function returns true and hDC is not null, and this means that the handle is valid. The only change from my previous working code is that I substituted CreateDC() with PringDlg(). Infact CreateDC is not so useful to get the device context of the printer in that you have to specify the *name* of the printer, and this works with only one printer. PrintDlg() with mentionned flags, instead, returns the handle of the device context of the *default* printer, much more useful to me (and to everyone). I would take the occasion to thank hutch and Iczelion (and all of the other contributors) for their invaluable effort to provide us developer with such a great MASM32 package. I would also signal that inspecting WINDOWS.INC I found that one of the members of PRINTDLG structure should be corrected from lpPrinterSetupTemplateName to lpSetupTemplateName. Thanks. Alvise.
Posted on 2001-03-31 10:46:00 by alvise
Latest addition. I changed LAN and the code works. I continue being confused. In my home LAN the bitmap is correctly printed, but in my office LAN a blank sheet of paper gets out of the printer. I have been reading around experiences from other programmers, and someone says that there is not one secure way to print a bitmap for every operating system (95/98/NT/2000). Is there any final word about printing bitmaps in 95/98/NT/2000 ? Regards. Alvise.
Posted on 2001-03-31 11:24:00 by alvise
Alvise, I ported the bitmap sample in win32.hlp file. It works until now everywhere I tried it. I can mail it to you, so you can test it yourself. vesa
Posted on 2001-04-02 01:58:00 by vesa
I had a look at win32.hlp too, but after your advise I will carefully study it again to find the differences. My win32.hlp is 24MB approx., and it is dated march 14th, 1997. Maybe it is too old. I will ask you the code only if I can't solve it myself. Thanks you very much for your kind attention, and regards from Alvise. P.S.: where can I find a more recent win32.hlp ?? This message was edited by alvise, on 4/2/2001 5:54:52 AM
Posted on 2001-04-02 05:54:00 by alvise
alvise, my win32.hlp is dated 11. August 1999. Where it is from? I don't know anymore. The newest platform SDK has the same sample. vesa
Posted on 2001-04-03 01:36:00 by vesa
Hi vesa. I revised my "printing a bitmap" code vs my win32.hlp and it looks OK, but I can't still print. I also searched the Internet for a recent win32.hlp, but I only found a compiled version (win32.chi) that does not cover winNT and win2k. Can you please send me your "printing a bitmap" code ? I would appreciate it much, because it could solve my problem. Many thanks. Alvise. e-mail: alvise@hochfeiler.it ------------- P.S.: i published some code (both in win32asm and C++) at: www.hochfeiler.it/alvise This message was edited by alvise, on 4/4/2001 8:37:13 AM This message was edited by alvise, on 4/4/2001 8:38:42 AM
Posted on 2001-04-04 08:35:00 by alvise
you should also care about the device capabilities of your printer, because some printers (like HP Laserjet) dont support some GDI modes, like 32 bit color depth or reverse blits (with negative height). I had an example, where I must mirror my bitmap before printing. In another case I had to reduce my 32bit memory bitmap to a 24 bit one before printing. My other printer (Epson Stylus) did all the things itself and printed everything fine. (blame on HP :cool:)
Posted on 2001-04-05 05:22:00 by beaster
Yes, some strange things happen. Anycase I solved my problem and want to inform you all. I used BitBlt to copy a bitmap from its device context to the device context of the printer. This worked only when the device context of the printer was obtained using GetDC. Then I changed GetDC to PrintDlg, and BitBlt didn't work anymore. Looking at the source code that Vesa kindly sent me, and at the Thomas's example in the example2 directory of MASM32 v.6, I decided to use *StretchBlt* instead of BitBlt, and now my routine is happily printing. I would also point out that Microsoft doesn't release win32.hlp anymore, because all its documentation is now released in the compiled help version (.chm, I hate it). Anycase the latest win32.hlp version available (before compiled help) can be downloaded at this address: http://www.borland.com/techpubs/bcppbuilder/v5/updates/ent.html (look for B5MS.ZIP, 17MB size approx). That's all. Thanks all. Alvise.
Posted on 2001-04-06 03:22:00 by alvise