CPrintDialog    printDlg(FALSE);
         printDlg.GetDefaults(); LPDEVMODE  lpDevMode;    
    
lpDevMode=(LPDEVMODE)GlobalLock(printDlg.m_pd.hDevMode);    
if(lpDevMode)    
{    
lpDevMode->dmPaperSize=DMPAPER_A4;     
lpDevMode->dmOrientation=DMORIENT_LANDSCAPE;    
}    
GlobalUnlock(printDlg.m_pd.hDevMode);   

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

解决方案 »

  1.   

    参考一下资料
    http://support.microsoft.com/default.aspx?scid=kb;en-us;214617
    How to change the page orientation without interacting with the common Print dialog box in Visual C++
    http://www.codeguru.com/forum/showthread.php?t=347227
    LPDEVMODE ChangeDevMode(HWND hWnd, char *pDevice, BYTE pageOrientation)
    {
       HANDLE      hPrinter;
       LPDEVMODE   pDevMode;
       DWORD       dwNeeded, dwRet;   /* Start by opening the printer */
       if (!OpenPrinter(pDevice, &hPrinter, NULL))
           return NULL;   /*
        * Step 1:
        * Allocate a buffer of the correct size.
        */
       dwNeeded = DocumentProperties(hWnd,
           hPrinter,       /* handle to our printer */
           pDevice,        /* Name of the printer */
           NULL,           /* Asking for size so */
           NULL,           /* these are not used. */
           0);             /* Zero returns buffer size. */
       pDevMode = (LPDEVMODE)malloc(dwNeeded);   /*
        * Step 2:
        * Get the default DevMode for the printer and
        * modify it for our needs.
        */
       dwRet = DocumentProperties(hWnd,
           hPrinter,
           pDevice,
           pDevMode,       /* The address of the buffer to fill. */
           NULL,           /* Not using the input buffer. */
           DM_OUT_BUFFER); /* Have the output buffer filled. */
       if (dwRet != IDOK)
       {
           /* if failure, cleanup and return failure */
           free(pDevMode);
           ClosePrinter(hPrinter);
           return NULL;
       }   /*
        * Make changes to the DevMode which are supported.
        */
    if (pDevMode->dmFields & DM_ORIENTATION)       
    {
           /* if the printer supports paper orientation, set it*/
           pDevMode->dmOrientation = pageOrientation;       
    }
       /*
        * Step 3:
        * Merge the new settings with the old.
        * This gives the driver a chance to update any private
        * portions of the DevMode structure.
        */
       dwRet = DocumentProperties(hWnd,
           hPrinter,
           pDevice,
           pDevMode,       /* Reuse our buffer for output. */
           pDevMode,       /* Pass the driver our changes. */
           DM_IN_BUFFER |  /* Commands to Merge our changes and */
           DM_OUT_BUFFER); /* write the result. */   /* Done with the printer */
       ClosePrinter(hPrinter);   if (dwRet != IDOK)
       {
           /* if failure, cleanup and return failure */
           free(pDevMode);
           return NULL;
       }   /* return the modified DevMode structure */
       return pDevMode;}void CPCLViewerView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
    {
    if (pInfo->m_bDirect)
    {
    // direct printing  'printto' ?
    CCommandLineInfo* pCmdInfo = AfxGetApp()->m_pCmdInfo; if (pCmdInfo != NULL)
    {
    if (pCmdInfo->m_nShellCommand == CCommandLineInfo::FilePrintTo)
    {
                    LPSTR pBuffer = pCmdInfo->m_strPrinterName.GetBuffer();

    // m_Orientation obtained from the file
    // could be DMORIENT_PORTRAIT or DMORIENT_LANDSCAPE
    BYTE pageOrientation = GetDocument()->m_Orientation;
    LPDEVMODE lpDevMode  = ChangeDevMode(m_hWnd, pBuffer, pageOrientation); pDC->ResetDC(lpDevMode);

    pCmdInfo->m_strPrinterName.ReleaseBuffer();
    }
    }
    } // other stuff.....
    }
    http://www.codeguru.com/forum/archive/index.php/t-155357.html