Printer DC
-
Hi, I have to print images from my application. For doing this, I created a Printer DC and the images is painted using 'StretchDIBits'. Now the printing is OK. The problem is of the sheet size. How can i change the print size according to the different sheet sizes supported by the specified printer? Please help. Regards, Kumar
Krishnakumar
-
Hi, I have to print images from my application. For doing this, I created a Printer DC and the images is painted using 'StretchDIBits'. Now the printing is OK. The problem is of the sheet size. How can i change the print size according to the different sheet sizes supported by the specified printer? Please help. Regards, Kumar
Krishnakumar
For print you can use also of
PrintDlg
and also see this structureDEVMODE
on MSDN
WhiteSky
-
For print you can use also of
PrintDlg
and also see this structureDEVMODE
on MSDN
WhiteSky
Hi, Actually i want to know that, whether the printer DC is to be resized according to the paper sizes. If yes, how can i change the size? Me already checked with the following code for( int nIndex = 0; nIndex < nNumPapers; nIndex++ ) { CString csPaperSize = _T( pPaperNames ); /* Got from GetDeviceCapabilities */ memcpy( pDevModeOutput->dmFormName, csPaperSize.GetBuffer(csPaperSize.GetLength()), 32) ; HDC hTempHandle; pDevModeOutput->dmFields |= DM_FORMNAME; CString csTemp( _T( "" )); hTempHandle = ResetDC( hDc, pDevModeOutput ); nPixelX = GetDeviceCaps( hDc, HORZRES ); nPixelY = GetDeviceCaps( hDc, VERTRES ); csTemp.Format( _T( "%s : %d, %d" ), pDevModeOutput->dmFormName, nPixelX, nPixelY ); AfxMessageBox( csTemp ); } but the nPixelX, nPixelY always getting the same for all paper sizes Regards, Krishnakumar
-
Hi, I have to print images from my application. For doing this, I created a Printer DC and the images is painted using 'StretchDIBits'. Now the printing is OK. The problem is of the sheet size. How can i change the print size according to the different sheet sizes supported by the specified printer? Please help. Regards, Kumar
Krishnakumar
Hopefully this little cut & paste will help you... Iain.
szPrintablePixelsMax.cx= ::GetDeviceCaps (hPrinterDC, HORZRES);
szPrintablePixelsMax.cy= ::GetDeviceCaps (hPrinterDC, VERTRES);
szPrintableArea.cx = ::GetDeviceCaps (hPrinterDC, HORZSIZE);
szPrintableArea.cy = ::GetDeviceCaps (hPrinterDC, VERTSIZE); -
Hopefully this little cut & paste will help you... Iain.
szPrintablePixelsMax.cx= ::GetDeviceCaps (hPrinterDC, HORZRES);
szPrintablePixelsMax.cy= ::GetDeviceCaps (hPrinterDC, VERTRES);
szPrintableArea.cx = ::GetDeviceCaps (hPrinterDC, HORZSIZE);
szPrintableArea.cy = ::GetDeviceCaps (hPrinterDC, VERTSIZE); -
Hi, Actually i want to know that, whether the printer DC is to be resized according to the paper sizes. If yes, how can i change the size? Me already checked with the following code for( int nIndex = 0; nIndex < nNumPapers; nIndex++ ) { CString csPaperSize = _T( pPaperNames ); /* Got from GetDeviceCapabilities */ memcpy( pDevModeOutput->dmFormName, csPaperSize.GetBuffer(csPaperSize.GetLength()), 32) ; HDC hTempHandle; pDevModeOutput->dmFields |= DM_FORMNAME; CString csTemp( _T( "" )); hTempHandle = ResetDC( hDc, pDevModeOutput ); nPixelX = GetDeviceCaps( hDc, HORZRES ); nPixelY = GetDeviceCaps( hDc, VERTRES ); csTemp.Format( _T( "%s : %d, %d" ), pDevModeOutput->dmFormName, nPixelX, nPixelY ); AfxMessageBox( csTemp ); } but the nPixelX, nPixelY always getting the same for all paper sizes Regards, Krishnakumar
-
Me already tried the below code szPrintablePixelsMax.cx= ::GetDeviceCaps (hPrinterDC, HORZRES); szPrintablePixelsMax.cy= ::GetDeviceCaps (hPrinterDC, VERTRES); it always returns the same value for all sheet sizes. Regards, Kumar
That's not a surprise - its returning the DPI for the printer. There were FOUR lines in the message I posted, and you are looking at the wrong two. Try the other two lines. Iain.
-
That's not a surprise - its returning the DPI for the printer. There were FOUR lines in the message I posted, and you are looking at the wrong two. Try the other two lines. Iain.
As per MSDN, the below code returns the width and height in pixels, int nX = GetDeviceCaps( hDc, HORZRES ); int nY = GetDeviceCaps( hDc, VERTRES ); Actually i meant that for some of the printers ( HP LaserJet 4250 PCL 5e ), the code gives different values for different sheet sizes. But the problem is that some of other printers (hp deskjet 3500 series) gives the same values for different papaer sizes. I am setting the size using the "DocumentProperties" function as below pDevModeOutput->dmPaperSize = 0; // It should be set to zero if paper length and width are given seperately pDevModeOutput->dmPaperLength = pPaperSizes[nSelection].y; // 2100 in case A4 pDevModeOutput->dmPaperWidth = pPaperSizes[nSelection].x; // 2970 in case A4 CString csPaperSize = _T( "" ); memcpy( pDevModeOutput->dmFormName, csPaperSize.GetBuffer(csPaperSize.GetLength()), 32) ; pDevModeOutput->dmPrintQuality = -1; pDevModeOutput->dmYResolution = 0; //pDevModeOutput->dmScale = 90; pDevModeOutput->dmFields = DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH | DM_FORMNAME | DM_PRINTQUALITY | DM_YRESOLUTION; // DM_SCALE; // To get the Devmode structure filled if( !DocumentProperties( NULL, // handle to parent window hHandle, // handle to printer object csPrinterName.GetBuffer(csPrinterName.GetLength()+1), // device name pDevModeOutput, // modified device mode 0, // original device mode DM_IN_BUFFER// mode options )) { return; }
Krishnakumar
-
Hi, The way I change the paper size is given below pDevModeOutput->dmPaperSize = 0; // It should be set to zero if paper length and width are given seperately pDevModeOutput->dmPaperLength = pPaperSizes[nSelection].y; // 2970 in case A4 pDevModeOutput->dmPaperWidth = pPaperSizes[nSelection].x; // 2100 in case A4 CString csPaperSize = _T( "" ); memcpy( pDevModeOutput->dmFormName, csPaperSize.GetBuffer(csPaperSize.GetLength()), 32) ; pDevModeOutput->dmPrintQuality = -1; pDevModeOutput->dmYResolution = 0; //pDevModeOutput->dmScale = 90; pDevModeOutput->dmFields = DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH | DM_FORMNAME | DM_PRINTQUALITY | DM_YRESOLUTION; // DM_SCALE; // To get the Devmode structure filled if( !DocumentProperties( NULL, // handle to parent window hHandle, // handle to printer object csPrinterName.GetBuffer(csPrinterName.GetLength()+1), // device name pDevModeOutput, // modified device mode 0, // original device mode DM_IN_BUFFER// mode options )) { return; } hDc = CreateDC( NULL, csPrinterName.operator LPCTSTR(), NULL, pDevModeOutput ); nDPIX = GetDeviceCaps( hDc, LOGPIXELSX ); nDPIY = GetDeviceCaps( hDc, LOGPIXELSY ); Actually I don't know the procedure that how to change the paper size. I think some mistakes are there in my code or something is missing. I have to draw a rectangle that is fit into the specified paper size. Please reply.
Krishnakumar
-
Hi, The way I change the paper size is given below pDevModeOutput->dmPaperSize = 0; // It should be set to zero if paper length and width are given seperately pDevModeOutput->dmPaperLength = pPaperSizes[nSelection].y; // 2970 in case A4 pDevModeOutput->dmPaperWidth = pPaperSizes[nSelection].x; // 2100 in case A4 CString csPaperSize = _T( "" ); memcpy( pDevModeOutput->dmFormName, csPaperSize.GetBuffer(csPaperSize.GetLength()), 32) ; pDevModeOutput->dmPrintQuality = -1; pDevModeOutput->dmYResolution = 0; //pDevModeOutput->dmScale = 90; pDevModeOutput->dmFields = DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH | DM_FORMNAME | DM_PRINTQUALITY | DM_YRESOLUTION; // DM_SCALE; // To get the Devmode structure filled if( !DocumentProperties( NULL, // handle to parent window hHandle, // handle to printer object csPrinterName.GetBuffer(csPrinterName.GetLength()+1), // device name pDevModeOutput, // modified device mode 0, // original device mode DM_IN_BUFFER// mode options )) { return; } hDc = CreateDC( NULL, csPrinterName.operator LPCTSTR(), NULL, pDevModeOutput ); nDPIX = GetDeviceCaps( hDc, LOGPIXELSX ); nDPIY = GetDeviceCaps( hDc, LOGPIXELSY ); Actually I don't know the procedure that how to change the paper size. I think some mistakes are there in my code or something is missing. I have to draw a rectangle that is fit into the specified paper size. Please reply.
Krishnakumar