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

    A good way to Change the printer to landscape!

    I think the following code maybe very useful to some one of you to change the printer to landscape:
    Code:
    void CMyApp::SetLandscape()
    {
    	LPDEVNAMES lpDevNames;
    	LPTSTR lpszDriverName, lpszDeviceName, lpszPortName;
    	HANDLE hPrinter;      
    	PRINTDLG   pd;
    	
    	// 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);                 
    		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);       
    		}
    	}
    }
    Regards
    Jack
    ------------------------------------------------------------------------------
    XD++ MFC Library with 100% source code home : http://www.********.net

  2. #2
    Join Date
    Nov 2001
    Posts
    401

    ?

    What is m_hDevNames and m_hDevMode in the code, I am trying use this code in a dialog based application by the way.

    Thnaks !

    Pauli

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