Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Printer DC

Printer DC

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KKumarTG
    wrote on last edited by
    #1

    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

    H I 2 Replies Last reply
    0
    • K KKumarTG

      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

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      For print you can use also of PrintDlg and also see this structure DEVMODE on MSDN


      WhiteSky


      K 1 Reply Last reply
      0
      • H Hamid Taebi

        For print you can use also of PrintDlg and also see this structure DEVMODE on MSDN


        WhiteSky


        K Offline
        K Offline
        KKumarTG
        wrote on last edited by
        #3

        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

        H 1 Reply Last reply
        0
        • K KKumarTG

          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

          I Offline
          I Offline
          Iain Clarke Warrior Programmer
          wrote on last edited by
          #4

          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);

          K 1 Reply Last reply
          0
          • I Iain Clarke Warrior Programmer

            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);

            K Offline
            K Offline
            KKumarTG
            wrote on last edited by
            #5

            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

            I 1 Reply Last reply
            0
            • K KKumarTG

              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

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              Did you see DEVMODE ? here[^] (dmPaperSize )


              WhiteSky


              K 1 Reply Last reply
              0
              • K KKumarTG

                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

                I Offline
                I Offline
                Iain Clarke Warrior Programmer
                wrote on last edited by
                #7

                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.

                K 1 Reply Last reply
                0
                • I Iain Clarke Warrior Programmer

                  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.

                  K Offline
                  K Offline
                  KKumarTG
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • H Hamid Taebi

                    Did you see DEVMODE ? here[^] (dmPaperSize )


                    WhiteSky


                    K Offline
                    K Offline
                    KKumarTG
                    wrote on last edited by
                    #9

                    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

                    H 1 Reply Last reply
                    0
                    • K KKumarTG

                      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

                      H Offline
                      H Offline
                      Hamid Taebi
                      wrote on last edited by
                      #10

                      See Set up/change printer orientation and select paper type/size[^]


                      WhiteSky


                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups