CPrintInfo or CPrintDlg ???中哪个成员变量要改变吗????

解决方案 »

  1.   

    BOOL MySetPrinter(LPTSTR pPrinterName, short dmOrientation,short dmPaperSize)
    {
    HANDLE hPrinter = NULL;
    DWORD dwNeeded = 0;
    PRINTER_INFO_2 *pi2 = NULL;
    DEVMODE *pDevMode = NULL;
    PRINTER_DEFAULTS pd;
    BOOL bFlag;
    LONG lFlag; // Open printer handle (on Windows NT, you need full-access because you
    // will eventually use SetPrinter)...
    ZeroMemory(&pd, sizeof(pd));
    pd.DesiredAccess = PRINTER_ALL_ACCESS;
    bFlag = OpenPrinter(pPrinterName, &hPrinter, &pd);
    if (!bFlag || (hPrinter == NULL))
    return FALSE; // The first GetPrinter tells you how big the buffer should be in 
    // order to hold all of PRINTER_INFO_2. Note that this should fail with 
    // ERROR_INSUFFICIENT_BUFFER.  If GetPrinter fails for any other reason 
    // or dwNeeded isn't set for some reason, then there is a problem...
    SetLastError(0);
    bFlag = GetPrinter(hPrinter, 2, 0, 0, &dwNeeded);
             if ((!bFlag) && (GetLastError() != ERROR_INSUFFICIENT_BUFFER) || 
             (dwNeeded == 0))
    {
    ClosePrinter(hPrinter);
    return FALSE;
    } // Allocate enough space for PRINTER_INFO_2...
    pi2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, dwNeeded);
    if (pi2 == NULL)
    {
    ClosePrinter(hPrinter);
    return FALSE;
    } // The second GetPrinter fills in all the current settings, so all you
    // need to do is modify what you're interested in...
    bFlag = GetPrinter(hPrinter, 2, (LPBYTE)pi2, dwNeeded, &dwNeeded);
    if (!bFlag)
    {
    GlobalFree(pi2);
    ClosePrinter(hPrinter);
    return FALSE;
    } // If GetPrinter didn't fill in the DEVMODE, try to get it by calling
    // DocumentProperties...
    if (pi2->pDevMode == NULL)
    {
    dwNeeded = DocumentProperties(NULL, hPrinter,
    pPrinterName,
    NULL, NULL, 0);
    if (dwNeeded <= 0)
    {
    GlobalFree(pi2);
    ClosePrinter(hPrinter);
    return FALSE;
    } pDevMode = (DEVMODE *)GlobalAlloc(GPTR, dwNeeded);
    if (pDevMode == NULL)
    {
    GlobalFree(pi2);
    ClosePrinter(hPrinter);
    return FALSE;
    } lFlag = DocumentProperties(NULL, hPrinter,
    pPrinterName,
    pDevMode, NULL,
    DM_OUT_BUFFER);
    if (lFlag != IDOK || pDevMode == NULL)
    {
    GlobalFree(pDevMode);
    GlobalFree(pi2);
    ClosePrinter(hPrinter);
    return FALSE;
    } pi2->pDevMode = pDevMode;
    } // Driver is reporting that it doesn't support this change...
    // if (!(pi2->pDevMode->dmFields & DM_ORIENTATION))
    // {
    // GlobalFree(pi2);
    // ClosePrinter(hPrinter);
    // if (pDevMode)
    // GlobalFree(pDevMode);
    // return FALSE;
    // } // Specify exactly what we are attempting to change... /* Update By Masatoshi [email protected] in 2003.2.25
     * When printing by RICOH IPSiO Color 5000(Compatible Driver),
     * Fail to change papersize.
     * Tring to exchange "Changing orientation" and "Changing papersize",
     * (I expected to fail to change orientation But...)
     * then both changing is succeed.
     */ /* Delete By Masatoshi [email protected] in 2003.2.25
    pi2->pDevMode->dmFields = DM_PAPERSIZE;
    pi2->pDevMode->dmPaperSize = dmPaperSize;
    lFlag = DocumentProperties(NULL, hPrinter,
      pPrinterName,
      pi2->pDevMode, pi2->pDevMode,
      DM_IN_BUFFER | DM_OUT_BUFFER);
    if (lFlag != IDOK)
    {
    GlobalFree(pi2);
    ClosePrinter(hPrinter);
    if (pDevMode)
    GlobalFree(pDevMode);
    return FALSE;
    }
    bFlag = SetPrinter(hPrinter, 2, (LPBYTE)pi2, 0);
    if (!bFlag)
    {
    GlobalFree(pi2);
    ClosePrinter(hPrinter);
    if (pDevMode)
    GlobalFree(pDevMode);
    return FALSE;
    }
    */
    pi2->pDevMode->dmFields = DM_ORIENTATION;
    pi2->pDevMode->dmOrientation = dmOrientation;
    lFlag = DocumentProperties(NULL, hPrinter,
      pPrinterName,
      pi2->pDevMode, pi2->pDevMode,
      DM_IN_BUFFER | DM_OUT_BUFFER);
    if (lFlag != IDOK)
    {
    GlobalFree(pi2);
    ClosePrinter(hPrinter);
    if (pDevMode)
    GlobalFree(pDevMode);
    return FALSE;
    }
    bFlag = SetPrinter(hPrinter, 2, (LPBYTE)pi2, 0);
    if (!bFlag)
    {
    GlobalFree(pi2);
    ClosePrinter(hPrinter);
    if (pDevMode)
    GlobalFree(pDevMode);
    return FALSE;
    }
    // Add Start By Masatoshi [email protected] in 2003.2.25
    pi2->pDevMode->dmFields = DM_PAPERSIZE;
    pi2->pDevMode->dmPaperSize = dmPaperSize;
    lFlag = DocumentProperties(NULL, hPrinter,
      pPrinterName,
      pi2->pDevMode, pi2->pDevMode,
      DM_IN_BUFFER | DM_OUT_BUFFER);
    if (lFlag != IDOK)
    {
    GlobalFree(pi2);
    ClosePrinter(hPrinter);
    if (pDevMode)
    GlobalFree(pDevMode);
    return FALSE;
    }
    bFlag = SetPrinter(hPrinter, 2, (LPBYTE)pi2, 0);
    if (!bFlag)
    {
    GlobalFree(pi2);
    ClosePrinter(hPrinter);
    if (pDevMode)
    GlobalFree(pDevMode);
    return FALSE;
    }
    // Add End   By Masatoshi [email protected] in 2003.2.25 SendMessageTimeout(HWND_BROADCAST, WM_DEVMODECHANGE, 0L,
      (LPARAM)(LPCSTR)pPrinterName,
      SMTO_NORMAL, 1000, NULL);
    if (pi2)
    GlobalFree(pi2);
    if (hPrinter)
    ClosePrinter(hPrinter);
    if (pDevMode)
    GlobalFree(pDevMode);
    return TRUE;
    }
      

  2.   

    在CPageSetupDialog类中具体我就不清楚了
      

  3.   

    是不是这样子:
    LPDEVMODE pMode=CPrintDialog::GetDevMode()得到设备模式指针
    通过以下语句改变横向纵向,没有验证过
    pMode->dmOrientation=DMORIENT_PORTRAIT;
    pMode->dmOrientation=DMORIENT_LANDSCAPE;