CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2000
    Location
    Germany, Franken
    Posts
    257

    changing printing to landscape first recognized the second time

    Hi, I'm doing some printing issues with MFC in VS.NET 2003.
    I want to change the format of printing to landscape. For that case I added these lines of code my OnBeginPrinting function:

    Code:
     // print this report in landscape
      LPDEVMODE lpPr = (LPDEVMODE)(((CPrintDialog *)(pInfo->m_pPD))->GetDevMode());
    	lpPr->dmOrientation = DMORIENT_LANDSCAPE;
    
      pwMain->OnBeginPrinting( this,pDC,pInfo,&m_pageGrid.m_wDataGrid,m_prtcols,&m_prtmap );
    When I execute my programm and choose the printing option the first preview is still in potrait event though the lines of codes written above where executed. The second time the preview is shown correctly in landscape.

    What do I make wrong?

    Akademos

  2. #2
    Join Date
    May 2004
    Posts
    2

    Re: changing printing to landscape first recognized the second time

    Hi, I am having the same problem.
    Did you find a solution?

  3. #3
    Join Date
    Apr 1999
    Posts
    3,585

    Re: changing printing to landscape first recognized the second time

    I think you may be setting the orientation too late. Try setting it in OnPrepareDC().
    Gort...Klaatu, Barada Nikto!

  4. #4
    Join Date
    Jun 2005
    Location
    Chennai , India
    Posts
    1,375

    Thumbs up Re: changing printing to landscape first recognized the second time

    this is the function for Lanscape:

    Code:
    void CIppiSampleApp::SetLandscape()
    {
        // Get default printer settings.
        PRINTDLG   pd;
    
        pd.lStructSize = (DWORD) sizeof(PRINTDLG);
        if (GetPrinterDeviceDefaults(&pd))
            {
            // Lock memory handle.
            DEVMODE FAR* pDevMode =
                (DEVMODE FAR*)::GlobalLock(m_hDevMode);
            LPDEVNAMES lpDevNames;
            LPTSTR lpszDriverName, lpszDeviceName, lpszPortName;
    //        HANDLE hPrinter;
    
    
            if (pDevMode)
                {
                // Change printer settings in here.
                pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
               // Unlock memory handle.
           lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
           lpszDriverName = (LPTSTR )lpDevNames + lpDevNames->wDriverOffset;
           lpszDeviceName = (LPTSTR )lpDevNames + lpDevNames->wDeviceOffset;
           lpszPortName   = (LPTSTR )lpDevNames + lpDevNames->wOutputOffset;
    
    //       ::OpenPrinter(lpszDeviceName, &hPrinter, NULL);
       //    ::DocumentProperties(NULL,hPrinter,lpszDeviceName,pDevMode,
    //                           pDevMode, DM_IN_BUFFER|DM_OUT_BUFFER);
    
           // Sync the pDevMode.
           // See SDK help for DocumentProperties for more info.
    //       ::ClosePrinter(hPrinter);
           ::GlobalUnlock(m_hDevNames);
           ::GlobalUnlock(m_hDevMode);
           }
        }
    }
    just call this function in ur button .. that will do ..




    if a post helped then dont forget to "Rate this post"
    It takes seconds for rating…that actually compensates the minutes taken for giving answers
    The biggest guru-mantra is: Never share your secrets with anybody. It will destroy you.
    Regards, Be generous->Rate people
    Jayender!!

  5. #5
    Join Date
    May 2004
    Posts
    2

    Re: changing printing to landscape first recognized the second time

    Moving my code from OnPreparePrinting into OnPrepareDC worked.
    All that's required is:

    Code:
    void CMyView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
    {
       LPDEVMODE pDevMode=NULL;
       if(pDC->IsPrinting())
       {
          pDevMode = pInfo->m_pPD->GetDevMode();
          if(pDevMode)
          {
             pDevMode->dmOrientation = GetReportOrientation();
             pDC->ResetDC(pDevMode);
          }
       }
       CExView::OnPrepareDC(pDC, pInfo);
    }
    Where GetReportOrientation() returns:
    DMORIENT_PORTRAIT or
    DMORIENT_LANDSCAPE


    Regards,
    Will.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured