发布网友 发布时间:2022-04-21 15:03
共2个回答
热心网友 时间:2023-11-13 03:58
//获取打印机详细信息,返回的指针用后必须以GlobalFree释放
PRINTER_INFO_2 *GetInfo2(HANDLE hPrinter)
{
PRINTER_INFO_2 *ppi2 = NULL;
DWORD cbNeeded = 0;
GetPrinter(hPrinter, 2, 0, 0, &cbNeeded);
if (cbNeeded)
{
ppi2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, cbNeeded);
if (ppi2)
{
if (!GetPrinter(hPrinter, 2, (LPBYTE)ppi2, cbNeeded, &cbNeeded))
{
GlobalFree((HGLOBAL)ppi2);
ppi2 = NULL;
}
}
}
return ppi2;
}
//打印机设置
BOOL SetInfo2(HANDLE hPrinter,PRINTER_INFO_2 *ppi2)
{
return::DocumentProperties(NULL, hPrinter,ppi2->pPrinterName,ppi2->pDevMode,ppi2->pDevMode,DM_IN_BUFFER|DM_OUT_BUFFER) == IDOK &&
::SetPrinter(hPrinter, 2, (LPBYTE)ppi2, 0);
}
//设置打印机的默认纸张和方向
//如果第二个参数为空,将不设置纸张尺寸(例如A4、A5)
//如果第三个参数为MAXDWORD,将不设置纸张类型(例如普通纸、信头纸)
//如果第四个参数为0,将不设置走纸方向
BOOL SetPaper(PRINTER_INFO_2 *ppi2,WORD wSize = MAXWORD, DWORD dwMediaType = MAXDWORD, short nOrientation = 0)
{
if(g_hPrinter == NULL || ppi2 == NULL)
return FALSE;
ppi2->pDevMode->dmFields = 0;
if(wSize != MAXWORD && wSize != ppi2->pDevMode->dmPaperSize)
{
ppi2->pDevMode->dmFields |= (DM_PAPERSIZE|DM_PAPERLENGTH|DM_PAPERWIDTH);
ppi2->pDevMode->dmPaperSize = wSize;
ppi2->pDevMode->dmPaperWidth = 0;
ppi2->pDevMode->dmPaperLength = 0;
}
if(dwMediaType != MAXDWORD && ppi2->pDevMode->dmMediaType != dwMediaType)
{
ppi2->pDevMode->dmFields |= DM_MEDIATYPE;
ppi2->pDevMode->dmMediaType = dwMediaType;
}
if(nOrientation != 0 && ppi2->pDevMode->dmOrientation != nOrientation)
{
ppi2->pDevMode->dmFields |= DM_ORIENTATION;
ppi2->pDevMode->dmOrientation = nOrientation;
}
if(ppi2->pDevMode->dmFields != 0)
return SetInfo2(g_hPrinter,ppi2);
else
return TRUE;
}
热心网友 时间:2023-11-13 03:59
自己多测试测试,相信你能行鍀追问...