DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Printer orientation

  1. #1
    James Chen Guest

    Printer orientation


    How to set up printer orientation programmatically? A doc shows a example
    like this:

    void CMyWinApp::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.
    ::ClosePrinter(hPrinter);
    ::GlobalUnlock(m_hDevNames);
    ::GlobalUnlock(m_hDevMode);
    }
    }
    }

    When compiling it, I got below error message:
    error C2039: 'OpenPrinter' : is not a member of '`global namespace''
    *.cpp(423) : error C2065: 'OpenPrinter' : undeclared identifier
    *.cpp(424) : error C2039: 'DocumentProperties' : is not a member of '`global
    namespace''
    *.cpp(424) : error C2065: 'DocumentProperties' : undeclared identifier
    *.cpp(429) : error C2039: 'ClosePrinter' : is not a member of '`global namespace''
    *.(429) : error C2065: 'ClosePrinter' : undeclared identifier

    Who can tell me what's wrong? Thanks in advance
    James



  2. #2
    Mark C Guest

    Re: Printer orientation


    "James Chen" <chenj@valuengine.com> wrote:
    >
    >How to set up printer orientation programmatically? A doc shows a example
    >like this:
    >
    >void CMyWinApp::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.
    > ::ClosePrinter(hPrinter);
    > ::GlobalUnlock(m_hDevNames);
    > ::GlobalUnlock(m_hDevMode);
    > }
    > }
    >}
    >
    >When compiling it, I got below error message:
    >error C2039: 'OpenPrinter' : is not a member of '`global namespace''
    >*.cpp(423) : error C2065: 'OpenPrinter' : undeclared identifier
    >*.cpp(424) : error C2039: 'DocumentProperties' : is not a member of '`global
    >namespace''
    >*.cpp(424) : error C2065: 'DocumentProperties' : undeclared identifier
    >*.cpp(429) : error C2039: 'ClosePrinter' : is not a member of '`global namespace''
    >*.(429) : error C2065: 'ClosePrinter' : undeclared identifier
    >
    >Who can tell me what's wrong? Thanks in advance
    >James
    >
    >


    You may need to include the following...

    Header: winspool.h.
    Import Library: winspool.lib.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center