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. PRINTDLG to CPrintInfo

PRINTDLG to CPrintInfo

Scheduled Pinned Locked Moved C / C++ / MFC
question
15 Posts 2 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.
  • _ _Flaviu

    Richard, is there a way to force printpreview to application, in such a way that user see nothing about it, just for retrieving CPrintInfo ? Could you tell me how ?

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #6

    Flaviu2 wrote:

    Could you tell me how ?

    Sorry, no, I have never tried such a thing.

    _ 2 Replies Last reply
    0
    • L Lost User

      Flaviu2 wrote:

      Could you tell me how ?

      Sorry, no, I have never tried such a thing.

      _ Offline
      _ Offline
      _Flaviu
      wrote on last edited by
      #7

      Ok, no pb, I have to digg in ... :)

      1 Reply Last reply
      0
      • L Lost User

        Flaviu2 wrote:

        Could you tell me how ?

        Sorry, no, I have never tried such a thing.

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #8

        Richard, I still have a question: I had tried to create manually an CPrintInfo object, just like that:

        	CPrintDialog pdlg(FALSE);
        	pdlg.GetDefaults();
        	HDC hDC = pdlg.CreatePrinterDC();
        	if(NULL != hDC)
        	{
        		m\_pPreviewInfo = new CPrintInfo;
        		m\_dcPrint.CreateCompatibleDC(CDC::FromHandle(hDC));
        		m\_pPreviewInfo->m\_rectDraw.left = 0;
        		m\_pPreviewInfo->m\_rectDraw.top = 0;
        		m\_pPreviewInfo->m\_rectDraw.right = m\_dcPrint.GetDeviceCaps(HORZRES);
        		m\_pPreviewInfo->m\_rectDraw.bottom = m\_dcPrint.GetDeviceCaps(VERTRES);
        		m\_pPreviewInfo->m\_bContinuePrinting = TRUE;
        		m\_pPreviewInfo->m\_bDirect = TRUE;
        		m\_pPreviewInfo->m\_bDocObject = FALSE;
        		m\_pPreviewInfo->m\_bPreview = TRUE;
        		m\_pPreviewInfo->m\_lpUserData = NULL;
        		m\_pPreviewInfo->m\_pPD = &pdlg;
        		m\_pPreviewInfo->SetMinPage(1);
        		m\_pPreviewInfo->SetMaxPage(2);
        		m\_nPages = m\_pPreviewInfo->m\_nNumPreviewPages;
        		m\_pPreviewDC = new CPreviewDC;
        		m\_pPreviewDC->SetAttribDC(m\_pPreviewInfo->m\_pPD->m\_pd.hDC);
        		m\_sizePrinterPPI.cx = m\_dcPrint.GetDeviceCaps(LOGPIXELSX);
        		m\_sizePrinterPPI.cy = m\_dcPrint.GetDeviceCaps(LOGPIXELSY);
        
        		m\_nPages = m\_pPreviewInfo->m\_nNumPreviewPages;
        		if (m\_nPages == 0)
        			m\_nPages = 1;
        		else if (m\_nPages > m\_nMaxPages)
        			m\_nPages = m\_nMaxPages;     // Sanity Check!
        	}
        

        where m_pPreviewInfo and m_pPreviewDC is protected members of CMyCustomPrintPreview:

        CPreviewDC\* m\_pPreviewDC;
        CPrintInfo\* m\_pPreviewInfo;
        

        of the first sight, I had do something wrong on the above code ? Because when I am trying to use m_pPreviewInfo object in CMyCustomPrintPreview::OnDraw, is crashing and I get an access violation on:

        _AFXEXT_INLINE UINT CPrintInfo::GetMaxPage() const
        { return m_pPD->m_pd.nMaxPage; }

        Thank you.

        L 1 Reply Last reply
        0
        • _ _Flaviu

          Richard, I still have a question: I had tried to create manually an CPrintInfo object, just like that:

          	CPrintDialog pdlg(FALSE);
          	pdlg.GetDefaults();
          	HDC hDC = pdlg.CreatePrinterDC();
          	if(NULL != hDC)
          	{
          		m\_pPreviewInfo = new CPrintInfo;
          		m\_dcPrint.CreateCompatibleDC(CDC::FromHandle(hDC));
          		m\_pPreviewInfo->m\_rectDraw.left = 0;
          		m\_pPreviewInfo->m\_rectDraw.top = 0;
          		m\_pPreviewInfo->m\_rectDraw.right = m\_dcPrint.GetDeviceCaps(HORZRES);
          		m\_pPreviewInfo->m\_rectDraw.bottom = m\_dcPrint.GetDeviceCaps(VERTRES);
          		m\_pPreviewInfo->m\_bContinuePrinting = TRUE;
          		m\_pPreviewInfo->m\_bDirect = TRUE;
          		m\_pPreviewInfo->m\_bDocObject = FALSE;
          		m\_pPreviewInfo->m\_bPreview = TRUE;
          		m\_pPreviewInfo->m\_lpUserData = NULL;
          		m\_pPreviewInfo->m\_pPD = &pdlg;
          		m\_pPreviewInfo->SetMinPage(1);
          		m\_pPreviewInfo->SetMaxPage(2);
          		m\_nPages = m\_pPreviewInfo->m\_nNumPreviewPages;
          		m\_pPreviewDC = new CPreviewDC;
          		m\_pPreviewDC->SetAttribDC(m\_pPreviewInfo->m\_pPD->m\_pd.hDC);
          		m\_sizePrinterPPI.cx = m\_dcPrint.GetDeviceCaps(LOGPIXELSX);
          		m\_sizePrinterPPI.cy = m\_dcPrint.GetDeviceCaps(LOGPIXELSY);
          
          		m\_nPages = m\_pPreviewInfo->m\_nNumPreviewPages;
          		if (m\_nPages == 0)
          			m\_nPages = 1;
          		else if (m\_nPages > m\_nMaxPages)
          			m\_nPages = m\_nMaxPages;     // Sanity Check!
          	}
          

          where m_pPreviewInfo and m_pPreviewDC is protected members of CMyCustomPrintPreview:

          CPreviewDC\* m\_pPreviewDC;
          CPrintInfo\* m\_pPreviewInfo;
          

          of the first sight, I had do something wrong on the above code ? Because when I am trying to use m_pPreviewInfo object in CMyCustomPrintPreview::OnDraw, is crashing and I get an access violation on:

          _AFXEXT_INLINE UINT CPrintInfo::GetMaxPage() const
          { return m_pPD->m_pd.nMaxPage; }

          Thank you.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #9

          I suspect that your CPrintDialog object is going out of scope thus causing this error. You should use new to create it before adding it to your CPrintInfo.

          _ 2 Replies Last reply
          0
          • L Lost User

            I suspect that your CPrintDialog object is going out of scope thus causing this error. You should use new to create it before adding it to your CPrintInfo.

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #10

            Yes, that was it ... :) Thank you. I am go with one step further ... I come beck soon.

            1 Reply Last reply
            0
            • L Lost User

              I suspect that your CPrintDialog object is going out of scope thus causing this error. You should use new to create it before adding it to your CPrintInfo.

              _ Offline
              _ Offline
              _Flaviu
              wrote on last edited by
              #11

              Yes, I had created dinamically (with new), but when I am trying to clean up in my class destructor, it crashing ...

              CPrintPreview::~CPrintPreview
              {
              if(NULL != m_pPrintDlg)
              delete m_pPrintDlg; // crash ! <----
              }

              weird ...

              L 1 Reply Last reply
              0
              • _ _Flaviu

                Yes, I had created dinamically (with new), but when I am trying to clean up in my class destructor, it crashing ...

                CPrintPreview::~CPrintPreview
                {
                if(NULL != m_pPrintDlg)
                delete m_pPrintDlg; // crash ! <----
                }

                weird ...

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #12

                Are you sure that your CPrintInfo object still exists at this point?

                _ 1 Reply Last reply
                0
                • L Lost User

                  Are you sure that your CPrintInfo object still exists at this point?

                  _ Offline
                  _ Offline
                  _Flaviu
                  wrote on last edited by
                  #13

                  I am sure that is not null ... is not enough ? How can assure of CPrintInfo existence ?

                  L 1 Reply Last reply
                  0
                  • _ _Flaviu

                    I am sure that is not null ... is not enough ? How can assure of CPrintInfo existence ?

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #14

                    It should be enough, but if it has somehow been corrupted, or already deleted then you will get a crash. The only way to check is via the debugger.

                    _ 1 Reply Last reply
                    0
                    • L Lost User

                      It should be enough, but if it has somehow been corrupted, or already deleted then you will get a crash. The only way to check is via the debugger.

                      _ Offline
                      _ Offline
                      _Flaviu
                      wrote on last edited by
                      #15

                      Thank you Richard, deleteing CPrintInfo object is excluded, the destructor is the only place where I explicity delete this object ... I have to dig in ...

                      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