Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing - more trouble

Posted on 2000-04-04
12
Medium Priority
?
307 Views
Last Modified: 2013-12-03
I generate a memory DC and Bitblt() to a printer DC.  I check to make sure the printer supports Bitblt().  When running with win2000 I have no problems, but with WinNT/98 the Bitblt() fails, but GetLastError() returns 0.
I have found that forcing one of my calculated numbers down a bit, it works.  I would like to find the flaw in my code though, so here it is:

iWidth = GetDeviceCaps(hPrintDC,PHYSICALWIDTH);
iOffsetX = GetDeviceCaps(hPrintDC,PHYSICALOFFSETX);
GetClientRect(hDisplay,&rect); // display
iPrintRatio = (iWidth -(2 * iOffsetX)) / (rect.right - rect.left);
/**
 *  ratio is 5 to 7 depending on pc/printer combination.  Works ok on 2000
 *  but need to use ratio -1 for NT/98
 */
SetMapMode(hPrintDC, MM_ANISOTROPIC);
SetWindowOrgEx(hPrintDC, 0, 0,NULL);
SetWindowExtEx(hPrintDC, 1, 1,NULL);
SetViewportOrgEx(hPrintDC, 0, 0,NULL);
SetViewportExtEx(hPrintDC, iPrintRatio,iPrintRatio,NULL);
BitBlt(hPrintDC, 0,0,rect.right-rect.left,rect.bottom-rect.top,hDisplayDC,0,0,SRCCOPY))

Thank You
0
Comment
Question by:marvinm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 1600 total points
ID: 2685029
SetMapMode(hPrintDC, MM_ANISOTROPIC);
SetWindowExt(hPrintDC, GetDeviceCaps(hDisplayDC, LOGPIXELSX), GetDeviceCaps(hDisplayDC, LOGPIXELSY));
SetViewportExt(hPrintDC, GetDeviceCaps(hPrintDC, LOGPIXELSX), GetDeviceCaps(hPrintDC, LOGPIXELSY));
SetWindowOrg(hPrintDC, 0, 0);
SetViewportOrg(hPrintDC, 0, 0);
0
 
LVL 1

Author Comment

by:marvinm
ID: 2685218
Bitblt() still fails, but at least GetLastError() returns an integer 87.  The only error code I could find was
ERROR_INVALID_PARAMETER, but this is listed as
/* New 3.0 network related error codes */
0
 
LVL 23

Expert Comment

by:chensu
ID: 2685264
Make sure the DC handles are valid. GetLastError returns correct information only on Windows NT/2000 when BitBlt returns zero.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 1

Author Comment

by:marvinm
ID: 2685333
I am tesing on 98, but I will switch on NT to try and get a valid error code.  It always seems to work from 2000.
If I do the following, it works from my 98 machine:
SetViewportExt(hPrintDC, GetDeviceCaps(hPrintDC, LOGPIXELSX)-100, GetDeviceCaps(hPrintDC, LOGPIXELSY)-100);
Thank You

0
 
LVL 23

Expert Comment

by:chensu
ID: 2685481
It has something to do with the specific printer driver. Try other printers.
0
 
LVL 1

Author Comment

by:marvinm
ID: 2690317
I have tried with several combinations of PCs and printers.  Using win200 and any printer it seems to work fine.  With 98/NT I always need to subtract off a certain amount.  So far it always works if I subtract at least 25, ie:
SetViewportExt(hPrintDC, GetDeviceCaps(hPrintDC, LOGPIXELSX)-25, GetDeviceCaps(hPrintDC, LOGPIXELSY)-25);

This is acceptable.  My last concern is how to determine the maximum Y value to print to. When I was calculating the ratio as described above I used:

iMaxYPos = (GetDeviceCaps(hPrintDC,PHYSICALHEIGHT) - (2 * GetDeviceCaps(hPrintDC,PHYSICALOFFSETY))) / >iPrintRatio;

Thank You
0
 
LVL 23

Expert Comment

by:chensu
ID: 2691038
That's really strange.

The following code gets the printable rectangle.

RECT rcPage = { 0, 0,
                        ::GetDeviceCaps(hdc, HORZRES),
                        ::GetDeviceCaps(hdc, VERTRES) };
::DPtoLP(hdc, (LPPOINT)&rcPage, 2);
0
 
LVL 1

Author Comment

by:marvinm
ID: 2693756
Adjusted points from 200 to 400
0
 
LVL 1

Author Comment

by:marvinm
ID: 2693757
I just tried with another NT SP5 box network printing to an Optra on a 2000 box.  The Bitblt() fails and GetLastError() is integer 122.  I must be doing something fundamentally wrong here with all this strange behavior.  I can print images from PaintShopPro or Word with no problem.  Is there a better way to get my screen display to a printer?  I have little to experience with windows printing.  I will increase the points significantly if we can get this working. Thanks for your help. - mm
0
 
LVL 23

Expert Comment

by:chensu
ID: 2693975
Check out the following KB articles.

HOWTO: Capture and Print an Entire Window
http://support.microsoft.com/support/kb/articles/Q186/7/36.ASP

WINCAP Captures Screens Using DIB API
http://support.microsoft.com/support/kb/articles/Q97/1/93.ASP
0
 
LVL 1

Author Comment

by:marvinm
ID: 2704932
All set
0
 
LVL 23

Expert Comment

by:chensu
ID: 2705066
Great!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question