marvinm
asked on
Printing - more trouble
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,PHY SICALWIDTH );
iOffsetX = GetDeviceCaps(hPrintDC,PHY SICALOFFSE TX);
GetClientRect(hDisplay,&re ct); // 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,NU LL);
BitBlt(hPrintDC, 0,0,rect.right-rect.left,r ect.bottom -rect.top, hDisplayDC ,0,0,SRCCO PY))
Thank You
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,PHY
iOffsetX = GetDeviceCaps(hPrintDC,PHY
GetClientRect(hDisplay,&re
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,
SetViewportExtEx(hPrintDC,
BitBlt(hPrintDC, 0,0,rect.right-rect.left,r
Thank You
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Make sure the DC handles are valid. GetLastError returns correct information only on Windows NT/2000 when BitBlt returns zero.
ASKER
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
If I do the following, it works from my 98 machine:
SetViewportExt(hPrintDC, GetDeviceCaps(hPrintDC, LOGPIXELSX)-100, GetDeviceCaps(hPrintDC, LOGPIXELSY)-100);
Thank You
It has something to do with the specific printer driver. Try other printers.
ASKER
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,PH YSICALHEIG HT) - (2 * GetDeviceCaps(hPrintDC,PHY SICALOFFSE TY))) / >iPrintRatio;
Thank You
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,PH
Thank You
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);
The following code gets the printable rectangle.
RECT rcPage = { 0, 0,
::GetDeviceCaps(hdc, HORZRES),
::GetDeviceCaps(hdc, VERTRES) };
::DPtoLP(hdc, (LPPOINT)&rcPage, 2);
ASKER
Adjusted points from 200 to 400
ASKER
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
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
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
ASKER
All set
Great!
ASKER
ERROR_INVALID_PARAMETER, but this is listed as
/* New 3.0 network related error codes */