⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prntmrd.cpp

📁 PrintMirror 1.5 可用版 VC6 + DDK
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*   PrintMirror extracts individual page metafiles from Spool File.   Copyright (C) 2002-2004  Vipin Aravind   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA      Contact at vprnt@lycos.com */#ifdef _DEBUG#ifdef USERMODE_DRIVER#define DUMPMSG(msg) { if(msg) {OutputDebugStringA(msg); \     OutputDebugStringA("\r\n");} }  // I  am doing  this   to  flush.#else#define DUMPMSG(msg)   #endif#else#define DUMPMSG(msg)   #endif#ifndef USERMODE_DRIVER#include <stddef.h>#include <stdarg.h>#include <stdlib.h>#include <stdio.h>	#include <limits.h>#include <windef.h>#include <wingdi.h>#include <winerror.h>     extern "C" {#include <winddi.h>     }typedef BOOL   (APIENTRY *PFN_DrvEnableDriver)(ULONG,ULONG,PDRVENABLEDATA);typedef DHPDEV (APIENTRY *PFN_DrvEnablePDEV) (PDEVMODEW,LPWSTR,ULONG,HSURF*,ULONG,GDIINFO*,ULONG,PDEVINFO,HDEV,LPWSTR,HANDLE);#define COPYMEMORY(a,b,c)  {LPBYTE ptr = (LPBYTE)a; LPBYTE ptr1 = (LPBYTE)b;\     for (unsigned int i = 0 ; i < c; i++) *ptr++=*ptr1++;}#define ZEROMEMORY(a,b) { LPBYTE ptr = (LPBYTE)a; for(unsigned int i = 0 ;i < b ; i++) *ptr++ = 0;}#define FREE(X)  EngFreeMem(X)#define MALLOC(x) EngAllocMem(0,x,ALLOC_TAG);#define GETPRINTERDATA EngGetPrinterData#define GETPRINTERDRIVER EngGetPrinterDriver#else#define UNICODE#include   <stdlib.h>#include   <windows.h>#include   <winspool.h>#include   <stdio.h>#include   <wingdi.h>#include   <winddi.h>#define COPYMEMORY(a,b,c) CopyMemory(a,b,c)#define ZEROMEMORY(a,b) ZeroMemory(a,b)#define FREE(X)  free(X)#define MALLOC(x) malloc(x)#define GETPRINTERDATA GetPrinterData#define GETPRINTERDRIVER GetPrinterDriver#endif#include "prntmrd.h"     HANDLE hModDll;     struct DEVDATA{          HPALETTE hPalDefault ;          HDEV hEngineDevice;          HANDLE hPDriver;          HSURF  hSurf;          BOOL  binDocument;          DWORD dwJobId;          int Pages;          GDIINFO DevCaps;          DRVENABLEDATA pReal;          DHPDEV dhRPdev;           HMODULE hRealDriver;          int iDitherFormat;      };#define  PPDEV  DEVDATA*/*      Helper functions */PFN GetRealFunc (ULONG  index , DRVENABLEDATA *pded){     DRVFN  *func_ptr  = pded->pdrvfn;     int   numfuncs  = pded->c;     for(int i = 0 ; i <  numfuncs ; i++)     {          if(func_ptr->iFunc == index)               return func_ptr->pfn;          func_ptr++;     }     return  NULL;}BOOLFillDevInfo(        PPDEV   pPDev,        DEVINFO *pDevInfo,        int numcolors,        ULONG *palette,        LOGFONT *lf                ){     /* In case of any probs uncomment this      */     //     // Start with a clean slate.     //#ifdef USERMODE_DRIVER     ZEROMEMORY(pDevInfo, sizeof(DEVINFO));     pDevInfo->flGraphicsCaps = GCAPS_ALTERNATEFILL  |         GCAPS_HORIZSTRIKE    |         GCAPS_VERTSTRIKE     |         GCAPS_VECTORFONT | GCAPS_HALFTONE | GCAPS_OPAQUERECT |         GCAPS_BEZIERS |         GCAPS_WINDINGFILL;     pDevInfo->cxDither = 0;     pDevInfo->cyDither = 0;     switch(numcolors)     {     case 2:         pDevInfo->iDitherFormat = BMF_1BPP;         break;     case 16:         pDevInfo->iDitherFormat = BMF_4BPP;         break;     case 256:         pDevInfo->iDitherFormat = BMF_8BPP;         break;     case 0:         pDevInfo->iDitherFormat = BMF_24BPP;         break;     }     wcscpy((PWSTR)pDevInfo->lfDefaultFont.lfFaceName, lf->lfFaceName);     pDevInfo->lfDefaultFont.lfEscapement = lf->lfEscapement;     pDevInfo->lfDefaultFont.lfOrientation = lf->lfOrientation;     pDevInfo->lfDefaultFont.lfHeight = lf->lfHeight;     pDevInfo->lfDefaultFont.lfWidth = lf->lfWidth;     pDevInfo->lfDefaultFont.lfWeight = lf->lfWeight;     pDevInfo->lfDefaultFont.lfItalic = lf->lfItalic;     pDevInfo->lfDefaultFont.lfUnderline = lf->lfUnderline;     pDevInfo->lfDefaultFont.lfStrikeOut = lf->lfStrikeOut;     pDevInfo->lfDefaultFont.lfPitchAndFamily = lf->lfPitchAndFamily;     memcpy((void *)&(pDevInfo->lfAnsiVarFont), lf, sizeof(LOGFONT));     memcpy((void *)&(pDevInfo->lfAnsiFixFont), lf, sizeof(LOGFONT));     /*     if(numcolors)          pDevInfo->hpalDefault = EngCreatePalette(PAL_INDEXED, numcolors,palette, 0, 0, 0);     else     */          pDevInfo->hpalDefault = EngCreatePalette(PAL_BGR, 0, 0, 0, 0, 0);#else     pDevInfo->cFonts = 0;     pDevInfo->flGraphicsCaps2 = 0;     pDevInfo->cxDither = 0;     pDevInfo->cyDither = 0;#endif     pPDev->iDitherFormat = pDevInfo->iDitherFormat ;     pPDev->hPalDefault = pDevInfo->hpalDefault;     return(TRUE);}void GetRealDriverName(HANDLE hDriver,WCHAR RealDriverName[]){     DWORD cbNeeded;     if(GETPRINTERDATA(                 hDriver,    // handle to printer or print server                 L"RealDriverName",  // value name                 NULL,      // data type                 (LPBYTE)RealDriverName,       // configuration data buffer                 256,        // size of configuration data buffer                 &cbNeeded   // bytes received or required                  ) == ERROR_SUCCESS)          DUMPMSG("EnablePdev GetPrinter success");}//   I  have   put   34  functions    here   which  hold  relevance   for//    printer   drivers.static DRVFN  RasterFuncs[]  = {     //--------------------------------------------------------------------     // Document handling (general printing stuff)  [REQUIRED]     //--------------------------------------------------------------------     {INDEX_DrvEnablePDEV        ,   (PFN)DrvEnablePDEV          },     {INDEX_DrvCompletePDEV      ,   (PFN)DrvCompletePDEV        },     {INDEX_DrvDisablePDEV       ,   (PFN)DrvDisablePDEV         },     {INDEX_DrvEnableSurface     ,   (PFN)DrvEnableSurface       },     {INDEX_DrvDisableSurface    ,   (PFN)DrvDisableSurface      },     //     {INDEX_DrvAssertMode        ,   (PFN)DrvAssertMode          },     {INDEX_DrvResetPDEV         ,   (PFN)DrvResetPDEV           },#ifdef USERMODE_DRIVER     {INDEX_DrvDisableDriver     ,   (PFN)DrvDisableDriver       },#endif     //--------------------------------------------------------------------     // Brush     //--------------------------------------------------------------------     {INDEX_DrvRealizeBrush      ,   (PFN)DrvRealizeBrush        },     // Support for dithering of brushes     //     {INDEX_DrvDitherColor       ,   (PFN)DrvDitherColor            },     //--------------------------------------------------------------------     // Vector     //--------------------------------------------------------------------     {INDEX_DrvStrokePath        ,   (PFN)DrvStrokePath          },     {INDEX_DrvFillPath          ,   (PFN)DrvFillPath            },     {INDEX_DrvStrokeAndFillPath ,   (PFN)DrvStrokeAndFillPath   },     {INDEX_DrvPaint             ,   (PFN)DrvPaint               },     {INDEX_DrvLineTo ,              (PFN)DrvLineTo              },     //--------------------------------------------------------------------     // Bitmap     //--------------------------------------------------------------------     {INDEX_DrvBitBlt            ,   (PFN)DrvBitBlt              },     {INDEX_DrvCopyBits          ,   (PFN)DrvCopyBits            },     {INDEX_DrvStretchBlt        ,   (PFN)DrvStretchBlt          },#ifdef USERMODE_DRIVER     {INDEX_DrvStretchBltROP     ,   (PFN)DrvStretchBltROP       },#endif     //     {INDEX_DrvCreateDeviceBitmap ,  (PFN)DrvCreateDeviceBitmap  },     //     {INDEX_DrvDeleteDeviceBitmap ,  (PFN)DrvDeleteDeviceBitmap  },     //--------------------------------------------------------------------     // Text     //--------------------------------------------------------------------     {INDEX_DrvTextOut           ,   (PFN)DrvTextOut             },     //--------------------------------------------------------------------     // Escapes     //--------------------------------------------------------------------     {INDEX_DrvEscape            ,   (PFN)DrvEscape              },     {INDEX_DrvDrawEscape        ,   (PFN)DrvDrawEscape          },     //--------------------------------------------------------------------     // Font     //--------------------------------------------------------------------     /*        {INDEX_DrvDestroyFont       ,   (PFN)DrvDestroyFont         },        {INDEX_DrvQueryFont,        (PFN)DrvQueryFont       },        {INDEX_DrvQueryFontTree,    (PFN)DrvQueryFontTree   },        {INDEX_DrvQueryFontData,    (PFN)DrvQueryFontData   },        {INDEX_DrvFontManagement    ,   (PFN)DrvFontManagement      },        {INDEX_DrvQueryAdvanceWidths, (PFN)DrvQueryAdvanceWidths},      */     //--------------------------------------------------------------------     // Banding Support     //--------------------------------------------------------------------     {INDEX_DrvStartBanding      ,   (PFN)DrvStartBanding        },     {INDEX_DrvNextBand          ,   (PFN)DrvNextBand            },     {INDEX_DrvStartDoc          ,   (PFN)DrvStartDoc            },     {INDEX_DrvEndDoc            ,   (PFN)DrvEndDoc              },     {INDEX_DrvStartPage         ,   (PFN)DrvStartPage           },     {INDEX_DrvSendPage          ,   (PFN)DrvSendPage            },};/***************************Export   Functions   by  Dll   ************************/BOOL  CALLBACKDllMain(        HANDLE      hModule,        ULONG       ulReason,        PCONTEXT    pContext       ){     switch (ulReason)     {     case DLL_PROCESS_ATTACH:         {              hModDll = hModule;              /* keep the dll loaded */              WCHAR wName[MAX_PATH];              if (GetModuleFileName((HINSTANCE)hModule, wName, MAX_PATH))                    LoadLibrary(wName);              break;         }     case DLL_PROCESS_DETACH:         break;     }     return TRUE;}BOOL CALLBACKDrvEnableDriver(ULONG          iEngineVersion,        ULONG          cj,        DRVENABLEDATA *pded){     DUMPMSG("DrvEnableDriver");     if (iEngineVersion < DDI_DRIVER_VERSION) {          return(FALSE);     }     if (cj < sizeof(DRVENABLEDATA)) {          return(FALSE);     }     pded->iDriverVersion = DDI_DRIVER_VERSION_NT5;     pded->c = sizeof(RasterFuncs)/sizeof(DRVFN);     pded->pdrvfn = RasterFuncs;     return TRUE;}/*****I    have   seen    this   getting   called   at   the  first  print for a  spooler   session   and never   after******************/#ifdef USERMODE_DRIVERBOOL CALLBACK DrvQueryDriverInfo(DWORD dwMode, PVOID pBuffer, DWORD cbBuf, PDWORD pcbNeeded){     DUMPMSG("DrvQueryDriverInfo");     switch (dwMode)     {     case DRVQUERY_USERMODE:         *pcbNeeded = sizeof(DWORD);         if (pBuffer == NULL || cbBuf < sizeof(DWORD))         {              SetLastError(ERROR_INSUFFICIENT_BUFFER);              return FALSE;         }         *((PDWORD) pBuffer) = TRUE;         return TRUE;     default:         SetLastError(ERROR_INVALID_PARAMETER);         return FALSE;     }}#endifBOOL CALLBACK DrvStartBanding( SURFOBJ *pso, POINTL *pptl ){     DUMPMSG("DrvStartBanding");     return TRUE;}BOOL CALLBACK DrvNextBand( SURFOBJ *pso, POINTL *pptl ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -