CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Posts
    391

    Printer Paper Oritentation problem!

    Hi,
    I have a MFC app which conatians a chart control. I want to print this chart to the printer. I can do it using inbuilt properties for the chart but only in portrait mode.

    Is there a way to set the orientation of the printer to landscape before is start printing. I don't know any interface or classes that provide such functionality.
    Please Help!!!

  2. #2
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: Printer Paper Oritentation problem!

    The function shown below sets the orientation of the paper for a printer. Call this function before CView::OnFilePrint() and CView::OnFilePrintPreview() calls.
    Code:
    BOOL SetOrientation(BOOL bLandFl)
    {
    	PRINTDLG pd;
    	pd.lStructSize=(DWORD)sizeof(PRINTDLG);
    	BOOL bRet=GetPrinterDeviceDefaults(&pd);
    	if(bRet)
    	{
    		// protect memory handle with ::GlobalLock and ::GlobalUnlock
    		DEVMODE FAR *pDevMode=(DEVMODE FAR *)::GlobalLock(m_hDevMode);
    		// set orientation to landscape
    		 if(bLandFl)
    			pDevMode->dmOrientation=DMORIENT_LANDSCAPE;
    		else
    			pDevMode->dmOrientation=DMORIENT_PORTRAIT;
    		::GlobalUnlock(m_hDevMode);
    	}
    	else
    	{
    		CString s;
    		s.LoadString(IDS_STRING34116); //Failed to select the orientation of the paper for the printer
    		AfxMessageBox(s);
    	}
    	return bRet;
    }
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

  3. #3
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: Printer Paper Oritentation problem!

    I forgot to say that SetOrientation() function should be declared in your application class derrived from CWinApp. HGLOBAL m_hDevMode is protected member of the CWinApp class.
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

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