Partage
  • Partager sur Facebook
  • Partager sur Twitter

printing

C++ MFC

    16 octobre 2006 à 14:48:02

    Bonjour,

    J'aimerais pourvoir imprimer une partie de la fenetre de mon programme, et je ne sais comment faire.
    Tout d'abord j'ai deja creer le bouton 'imprimer" qui me lancer la fenêtre windows des imprimantes et le choix de celles-ci, il ne me reste plus qu'a faire le code pour imprimer la partie de l'ecran qui m'interresse, ou plutot pour commencer essayer d'imprimer tout l'ecran.
    Bien sur j'ai des erreurs il fallait s'en douter, donc je recommence tout avec votre aide...comment imprimer tout l'ecran de mon programme ?

    Merci
    • Partager sur Facebook
    • Partager sur Twitter
      17 octobre 2006 à 14:12:12

      La partie code de mon fichier EssaiDlg.cpp (main)

      void OnBeginPrinting(CDC *pDC, CPrintInfo* pInfo)
      {
          // maybe pre cache some pens or brushes, or modify the
          // properties of the DC
      }

      void OnPrint(CDC *pDC, CPrintInfo* pInfo)
      {
          // Do your drawing/printing exactly as you would in a
          // CView::OnDraw function. The CPrintInfo structure
          // will give you the bounds and the current page number
      }

      void OnEndPrinting(CDC *pDC, CPrintInfo* pInfo)
      {
          // Clean up pens or brushes, or restore the DC
      }



      void CEssaiDlg::Print()
      {
          CDC dc;
          CPrintDialog printDlg(FALSE);

          if (printDlgDoModal() == IDCANCEL)     // Get printer settings from user
              return;

          dc.Attach(printDlg.GetPrinterDC());     // Get and attach a printer DC
          dc.m_bPrinting = TRUE;

          CString strTitle;                       // Get the application title
          strTitle.LoadString(AFX_IDS_APP_TITLE);

          DOCINFO di;                             // Initialise print document details
          ::ZeroMemory (&di, sizeof (DOCINFO));
          di.cbSize = sizeof (DOCINFO);
          di.lpszDocName = strTitle;

          BOOL bPrintingOK = dc.StartDoc(&di);    // Begin a new print job

          // Get the printing extents and store in the m_rectDraw field of a
          // CPrintInfo object
          CPrintInfo Info;
          Info.m_rectDraw.SetRect(0,0,
                                  dc.GetDeviceCaps(HORZRES),
                                  dc.GetDeviceCaps(VERTRES));

          OnBeginPrinting(&dc, &Info);            // Call your "Init printing" function
          for (UINT page = 1Info.GetMinPage();
               page <= Info.GetMaxPage() && bPrintingOK;
               page++)
          {
              dc.StartPage();                     // begin new page
              Info.m_nCurPage = page;
              OnPrint(&dc, &Info);                // Call your "Print page" function
              bPrintingOK = (dc.EndPage() > 0);   // end page
          }
          OnEndPrinting(&dc, &Info);              // Call your "Clean up" function

          if (bPrintingOK)
              dc.EndDoc();                        // end a print job
          else
              dc.AbortDoc();                      // abort job.

          dc.DeleteDC();                          // delete the printer DC
      }



      Le fichier .h de la classe CPrntScreen
      #pragma once
      class CPrntScreen
      {
          public:
             CPrntScreen(char* sErrTxt=NULL, char* sCaption=NULL);
             virtual ~CPrntScreen();
             void DoPrntScreen(int fArea=0, int fOrientation=2, bool bDialog=false);

          protected:
             HANDLE DDBToDIB( CBitmap& bitmap, DWORD dwCompression, CPalette* pPal );
             char * sErrortext;
             char * sMsgCaption;
      };



      Ensuite on me dit de rajouter les 5 lignes qui suivent dans mon code ou je veux imprimer. je le fais et la j'ai 102 erreurs, beaucoup de ; non definies, donc il doit en manquer un quelque part mais j'en doute, ou alors j'ai zappé une définition.

      'CPrntScreen' : undeclared identifier
      'ScrCap' : undeclared identifier
      syntax error : identifier 'CPrntScreen'
      left of '->DoPrntScreen' must point to class/struct/union
      delete : cannot delete objects that are not pointers

      Alrs j'ai mon programme fait avec les MFC (oui je sais c'est nul mais je vais le changer Qt après). Donc j'ai une classe CEssaiDlg qui contient tout mon programme, et une CprntScreen qui contient les focntion d'impressions, et mes fonctions d'impressions je m'en sers dans CEssaiDlg::OnImprimer(//bouton imprimer), donc peut etre qu'il ya un probelme et qu'il ne connait pas les variables et fonction de l'autre classe, j'en sais rien je debute dans le monde des classes ^^


      CEssaiDlg::OnImprimer()
      {
              // TODO: Add your control notification handler code here

              CPrntScreen * ScrCap;
              ScrCap = new CPrntScreen()//create instance
              ScrCap->DoPrntScreen()//execute capture function
              delete ScrCap;  //remove instance
              ScrCap=NULL;
       
              return 0;
      }



      Au secours ^^ -ed-, m@teo21, :p
      • Partager sur Facebook
      • Partager sur Twitter

      printing

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown