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

📄 prntmrui.cpp

📁 PrintMirror 1.5 可用版 VC6 + DDK
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*   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 */#include "prntmrui.h"static UINT CALLBACK PropSheetPageProc(        HWND hwnd,        UINT uMsg,        LPPROPSHEETPAGE ppsp        ){     UINT toReturn = 0;     switch (uMsg)     {     case PSPCB_RELEASE:         toReturn = 0;         break;     case PSPCB_CREATE:         toReturn = 1;         break;     default:         break;     }     return toReturn;}/* *  Fill the PROPSHEETPAGE which will be passed to CPSUI */void FillInPropertyPage( PROPSHEETPAGE* psp, int idDlg, LPTSTR pszProc, DLGPROC pfnDlgProc,         VPrinterSettings *ps){     if(psp)     {          psp->dwSize = sizeof(PROPSHEETPAGE);          psp->dwFlags = PSP_USECALLBACK;          psp->hInstance = hModDLL ;          psp->pszTemplate = MAKEINTRESOURCE(idDlg);          psp->pfnDlgProc = pfnDlgProc;          psp->pszTitle = (LPTSTR)"";          psp->lParam = (LPARAM)ps;          psp->pfnCallback = PropSheetPageProc;     }}static BOOL CALLBACK DevicePropertiesDialog(        HWND hDlg,        UINT message,        UINT wParam,        LONG lParam){     switch (message)     {     case WM_NOTIFY:         switch (((NMHDR FAR *) lParam)->code)          {         case PSN_APPLY:             {                  WCHAR PrintMirrorName[256];                  GetPrintMirrorName(PrintMirrorName);                  DonotSharePrinterNT(PrintMirrorName,NULL,FALSE);             }             break;         }     default:         return FALSE;     }     return TRUE;   }POINT GetPaperSizeFromIndex(HANDLE hPrinter , int curSel , PDEVMODEW pDevmode , VPrinterSettings *ps){     int match = 0;     VDEVMODE *pDevMode = (VDEVMODE *)malloc(sizeof(VDEVMODE));     memcpy(pDevMode , pDevmode , sizeof(VDEVMODE));     wcscpy((WCHAR *)((LPBYTE)pDevMode + sizeof(DEVMODEW)), ps->PrinterName);     DWORD dwSize = DrvDeviceCapabilities(hPrinter,ps->pszPrinterName, DC_PAPERSIZE,              NULL,(PDEVMODE)pDevMode);     LPTSTR pvOutput = (LPTSTR)malloc(sizeof(POINT) * dwSize);         DrvDeviceCapabilities(hPrinter,ps->pszPrinterName, DC_PAPERSIZE, pvOutput,             (PDEVMODE)pDevMode);     POINT *PointList = (POINT *)pvOutput;     POINT PaperSize =  PointList[curSel];     free(pvOutput);     free(pDevMode);     return PaperSize;}WORD GetPaperFromIndex(HANDLE hPrinter , int curSel , PDEVMODEW pDevmode , VPrinterSettings *ps){     int match = 0;     VDEVMODE *pDevMode = (VDEVMODE *)malloc(sizeof(VDEVMODE));     memcpy(pDevMode , pDevmode , sizeof(VDEVMODE));     wcscpy((WCHAR *)((LPBYTE)pDevMode + sizeof(DEVMODEW)), ps->PrinterName);     DWORD dwSize = DrvDeviceCapabilities(hPrinter,ps->pszPrinterName, DC_PAPERS,              NULL,(PDEVMODE)pDevMode);     LPTSTR pvOutput = (LPTSTR)malloc(sizeof(WORD) * dwSize);         DrvDeviceCapabilities(hPrinter,ps->pszPrinterName, DC_PAPERS, pvOutput,             (PDEVMODE)pDevMode);     WORD *PointList = (WORD *)pvOutput;     WORD PaperSize =  PointList[curSel];     free(pvOutput);     free(pDevMode);     return PaperSize;}int GetPaperIndex(HANDLE hPrinter , short PaperSize , PDEVMODEW pDevmode, VPrinterSettings *ps){     int match = 0;     VDEVMODE *pDevMode = (VDEVMODE *)malloc(sizeof(VDEVMODE));     memcpy(pDevMode , pDevmode , sizeof(VDEVMODE));     wcscpy((WCHAR *)((LPBYTE)pDevMode + sizeof(DEVMODEW)), ps->PrinterName);     DWORD dwSize = DrvDeviceCapabilities(hPrinter,ps->pszPrinterName, DC_PAPERS,              NULL,(PDEVMODE)pDevMode);     LPTSTR pvOutput = (LPTSTR)malloc(sizeof(WORD) * dwSize);         DrvDeviceCapabilities(hPrinter,ps->pszPrinterName, DC_PAPERS, pvOutput,             (PDEVMODE)pDevMode);     WORD *PointList = (WORD *)pvOutput;     for(DWORD i = 0 ; i < dwSize ; i++)          if(PaperSize == PointList[i])          {               match = i;               break;          }     free(pvOutput);     free(pDevMode);     return match;}void SetPaperDimensions (HANDLE hPrinter ,HWND hDlg, int curSel ,         PDEVMODEW pDevmode , VPrinterSettings *ps){     POINT pt = GetPaperSizeFromIndex(hPrinter,curSel, (PDEVMODEW)(ps->ValidDevMode),ps);     //we just make this inches;     WCHAR Units[16];     if(/*IsInchDimensions()*/!(ps->DimensionUnits))     {          pt.x = (pt.x * 100)/2540;          pt.y = (pt.y * 100)/2540;          wcscpy(Units, L"inches");     }     else          wcscpy(Units,L"mms");     WCHAR PaperSize[1024];     if(ps->PaperOrient == DMORIENT_LANDSCAPE)     {          int temp = pt.x;          pt.x = pt.y;          pt.y = temp;     }     if(pt.x%10 && pt.y%10)          wsprintf(PaperSize,L"%d.%d x %d.%d %s",pt.x/10,pt.x%10,pt.y/10,pt.y%10,Units);     else if(pt.y%10)          wsprintf(PaperSize,L"%d x %d.%d %s",pt.x/10,pt.y/10,pt.y%10,Units);     else if(pt.x%10)          wsprintf(PaperSize,L"%d.%d x %d %s",pt.x/10,pt.x%10,pt.y/10,Units);     else          wsprintf(PaperSize,L"%d x %d %s",pt.x/10,pt.y/10,Units);     SetDlgItemText(hDlg , IDC_PAPERSIZE ,PaperSize); }void FillPaperCombo(HANDLE hPrinter ,HWND hDlg ,VDEVMODE *pDevmode , VPrinterSettings *ps){     VDEVMODE *pDevMode = (VDEVMODE *)malloc(sizeof(VDEVMODE));     memcpy(pDevMode , pDevmode , sizeof(VDEVMODE));     wcscpy((WCHAR *)((LPBYTE)pDevMode + sizeof(DEVMODEW)), ps->PrinterName);     DWORD dwSize = DrvDeviceCapabilities(hPrinter,ps->pszPrinterName, DC_PAPERNAMES,              NULL,(PDEVMODE)pDevMode);     LPTSTR pvOutput = (LPTSTR)malloc(dwSize * sizeof(WCHAR) * 64);         DrvDeviceCapabilities(hPrinter,ps->pszPrinterName, DC_PAPERNAMES, pvOutput,             (PDEVMODE)pDevMode);     HWND hwndPaper = GetDlgItem(hDlg ,IDC_PAPERCOMBO);     SendMessage(hwndPaper , CB_RESETCONTENT, (WPARAM)0, (LPARAM) 0 );     for(DWORD papers = 0 ; papers < dwSize ; papers++)     {          SendMessage( (HWND) hwndPaper,  CB_ADDSTRING, (WPARAM)0,                   (LPARAM)((papers * 64) + pvOutput));     }     free(pvOutput);     int match = GetPaperIndex(hPrinter ,ps->PaperSize, (PDEVMODEW)pDevMode,ps);       SendMessage( (HWND) hwndPaper, CB_SETCURSEL, (WPARAM)match, (LPARAM)0);     ps->PaperSize = GetPaperFromIndex(hPrinter , match , (PDEVMODEW)pDevmode ,ps);     SetPaperDimensions(hPrinter,hDlg,match, (PDEVMODEW)(ps->ValidDevMode),ps);     free(pDevMode);}static BOOL CALLBACK DocumentProperty(        HWND hDlg,        UINT message,        UINT wParam,        LONG lParam){     static BOOL fBlocking = FALSE;     static HBRUSH hBrushStatic = NULL;     switch (message)     {     case WM_INITDIALOG:         {              VPrinterSettings * ps = (VPrinterSettings *)(((PROPSHEETPAGE *)lParam)->lParam);              SetWindowLong(hDlg , DWL_USER , (LONG)lParam);              HWND hwnd = GetDlgItem(hDlg , IDC_PRINTERCOMBO);              /*                * Get the List of Printers to fill up the Printer combo and then set the                * printer name to the one in PrinterSettings                */              DWORD dwReturned,dwNeeded;              EnumPrinters (PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, NULL,                      0, &dwNeeded, &dwReturned) ;              LPBYTE pinfo4 = (LPBYTE)malloc (dwNeeded) ;              EnumPrinters (PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, (PBYTE) pinfo4,                      dwNeeded, &dwNeeded, &dwReturned) ;              for(DWORD printers = 0 ; printers < dwReturned ; printers++)              {                   LPTSTR PrinterName = ((PRINTER_INFO_4 *)pinfo4)[printers].pPrinterName;                   if(wcscmp(ps->pszPrinterName ,PrinterName))                         SendMessage( (HWND) hwnd,  CB_ADDSTRING, (WPARAM)0, (LPARAM)PrinterName );              }              WCHAR *RealDriverName;              LPBYTE pBuffer;              HANDLE hPrinter = GetPrinterInfo(&pBuffer , ps->pszPrinterName );              RealDriverName = (WCHAR *)((LPBYTE)(ps->ValidDevMode) + sizeof(DEVMODEW));              WCHAR RealDriverName1[256];              wcscpy(RealDriverName1 , RealDriverName);              //     if(!IsSpooler())              ValidateSetRealDriver(RealDriverName1);              int match = SendMessage( (HWND) hwnd, CB_FINDSTRINGEXACT, (WPARAM)-1 ,  (LPARAM)RealDriverName1);              wcscpy(ps->PrinterName , RealDriverName1);              SendMessage( (HWND) hwnd, CB_SETCURSEL, (WPARAM)match, (LPARAM)0);              free(pinfo4);              /* Fill the Paper combo and set with the value from PrinterSettings */              VDEVMODE * pDevMode;               pDevMode = ps->ValidDevMode;              FillPaperCombo(hPrinter , hDlg , pDevMode , ps);              /* Layout */              VPDEVMODE *PrivateDevmode = &((VDEVMODE *)(pDevMode))->pdm;              free(pBuffer);              ClosePrinter(hPrinter);              DUMPMSG("initdialog");         }                   break;     case WM_CTLCOLORSTATIC:         {              HWND hwnd = (HWND)lParam;              if(GetWindowLong(hwnd ,GWL_ID) == IDC_PAPERSIZE)              {                   SetTextColor((HDC)wParam,RGB(0,0,255));                   SetBkColor((HDC)wParam , GetSysColor(COLOR_BTNFACE));                   hBrushStatic = CreateSolidBrush ( GetSysColor (COLOR_BTNFACE)) ;                   return (LRESULT)hBrushStatic;              }         }         break;     case WM_LBUTTONDOWN:     case WM_MOUSEMOVE:     case WM_LBUTTONUP:         {              RECT rect;              RECT window;              GetWindowRect(hDlg, &window);              GetWindowRect(GetDlgItem(hDlg,IDC_PAPERSIZE) , &rect);              POINT pt;              pt.x = GET_X_LPARAM(lParam);              pt.y = GET_Y_LPARAM(lParam);              rect.left -= window.left;              rect.top -= window.top;              rect.right -= window.left;              rect.bottom -= window.top;              if(PtInRect(&rect , pt))              {                   SetCursor(LoadCursor(NULL,IDC_HAND));                        if(message == WM_LBUTTONDOWN)                   {                        PROPSHEETPAGE*  pPage = (PROPSHEETPAGE*)GetWindowLong( hDlg, DWL_USER );                        VPrinterSettings * ps = (VPrinterSettings *)(pPage->lParam);                        ps->DimensionUnits = ps->DimensionUnits ? FALSE : TRUE;                        LPBYTE pBuffer = NULL;                        HANDLE hPrinter = GetPrinterInfo(&pBuffer,                                 ps->pszPrinterName);                        int curSel = SendMessage( GetDlgItem(hDlg, IDC_PAPERCOMBO),                                CB_GETCURSEL, (WPARAM)0, (LPARAM)0);                        SetPaperDimensions(hPrinter,hDlg,curSel, (PDEVMODEW)(ps->ValidDevMode),ps);                        ClosePrinter(hPrinter);                        free(pBuffer);                   }              }              else              {                   SetCursor(LoadCursor(NULL,IDC_ARROW));              }         }         return FALSE;     case WM_COMMAND:         {              PROPSHEETPAGE*  pPage = (PROPSHEETPAGE*)GetWindowLong( hDlg, DWL_USER );              VPrinterSettings * ps = (VPrinterSettings *)(pPage->lParam);              switch(LOWORD(wParam))              {              case IDC_PRINTERCOMBO:                  {                       if(HIWORD(wParam) == CBN_SELCHANGE)                       {                            LPBYTE pBuffer;                            HANDLE hPrinter = GetPrinterInfo(&pBuffer , ps->pszPrinterName);                            VDEVMODE *pDevMode;                            pDevMode = ps->ValidDevMode;                            int curSel = SendMessage( GetDlgItem(hDlg, IDC_PRINTERCOMBO),                                    CB_GETCURSEL, (WPARAM)0, (LPARAM)0);                            SendMessage( GetDlgItem(hDlg, IDC_PRINTERCOMBO),                                    CB_GETLBTEXT, (WPARAM)curSel, (LPARAM)ps->PrinterName);                            FillPaperCombo(hPrinter , hDlg , pDevMode , ps);                            //PaperPreview(hDlg , ps);                            free(pBuffer);                            ClosePrinter(hPrinter);                       }                  }                  break;              case IDC_PAPERCOMBO:                  {                       if(HIWORD(wParam) == CBN_SELCHANGE)                       {

⌨️ 快捷键说明

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