非PCL驱动程序的DEVMODE问题

时间:2018-11-15 11:04:26

标签: printing

我使用了Microsoft (How To Modify Printer Settings with the DocumentProperties() Function)本身提供的代码 来更改打印机的某些设置:但是,在像PCL驱动程序一样工作时,PS驱动程序似乎对使用什么和忽略什么更具个人意识。以下代码是使用Windows 10 64位VC 2017编译的,使用的驱动程序是

  • Fiery MS MIC-4150 PS1.1
  • 柯尼卡美能达PS彩色激光级打印机
  • 柯尼卡美能达1200/1051 PCL
  • Microsoft打印为PDF
  • Microsoft PS类打印机

更具体地说:所有驱动程序似乎都接受“方向”,除PCL驱动程序外,其他任何人都不能接受“双工”。需要说的是,尽管不能通过DEVMODE结构更改设置,但可以通过供应商提供的对话框来更改所有设置。

{
HANDLE      hPrinter;
LPDEVMODE   pDevMode;
DWORD       dwNeeded, dwRet;

/* Start by opening the printer */
if (!OpenPrinter(pDevice, &hPrinter, NULL))
    return NULL;

/*
 * Allocate a buffer of the correct size.
 */
dwNeeded = DocumentProperties(NULL,
    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);

/*
 * Get the default DevMode for the printer and modify it for your needs.
 */
dwRet = DocumentProperties(NULL,
    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;
}
assert(pDevMode->dmFields & DM_ORIENTATION);
assert(pDevMode->dmFields & DM_DEFAULTSOURCE);
assert(pDevMode->dmFields & DM_COPIES);
assert(pDevMode->dmFields & DM_DUPLEX);
assert(pDevMode->dmFields & DM_COLOR);

pDevMode->dmCopies = 4711;
pDevMode->dmDuplex = DMDUP_VERTICAL;
pDevMode->dmColor = DMCOLOR_MONOCHROME;
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
pDevMode->dmFields = DM_COLOR | DM_DUPLEX | DM_COPIES | DM_ORIENTATION;

/*
 * Merge the new settings with the old. This gives the driver an opportunity to update any private portions of the DevMode structure.
 */
dwRet = DocumentProperties(NULL,
    hPrinter,
    pDevice,
    pDevMode,       /* Reuse our buffer for output. */
    pDevMode,       /* Pas the driver our changes. */
    DM_PROMPT | DM_IN_BUFFER |  /* Commands to Merge our changes and */
    DM_OUT_BUFFER); /* write the result. */

/* Finished 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;

}

有人对这个故事有更深入的了解吗?谢谢。

0 个答案:

没有答案