📄 docevent.cpp
字号:
/* PrintMirror extracts individual page metafiles from Spool File. Copyright (C) 2002-2003 V 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"#include "preview.h"int GetColorOrganisation(HDC hRealDC , DEVMODE *pbIn , ULONG palette[]){ int ret = 0; HDC compDC = CreateCompatibleDC(hRealDC); HBITMAP hBitmap = CreateCompatibleBitmap(hRealDC , 1 , 1); SelectObject(compDC , hBitmap); BITMAP bmp; GetObject(hBitmap ,sizeof(BITMAP), &bmp); if(bmp.bmBitsPixel <= 8) { switch(bmp.bmBitsPixel) { case 8: { BYTE bits = 0; for(int i = 0 ; i < 256 ; i++) { bits = i; SetBitmapBits(hBitmap , 1 , &bits); palette[i] = GetPixel(compDC , 0 , 0 ); } ret = 256; } break; case 1: { BYTE bits = 0; for(int i = 0 ; i < 2 ; i++) { SetBitmapBits(hBitmap , 1 , &bits); bits = ~bits; palette[i] = GetPixel(compDC , 0 , 0 ); } ret = 2; } break; case 4: { BYTE bits = 0; for(int i = 0 ; i < 16 ; i++) { bits = (i << 4); SetBitmapBits(hBitmap , 1 , &bits); palette[i] = GetPixel(compDC , 0 , 0 ); } ret = 16; } break; } } DeleteDC(compDC); DeleteObject(hBitmap); return ret;}void CreateGDIInfo(HANDLE hPrinter,VDEVMODE *pbIn){ WCHAR RealDriverName[256]; wcscpy(RealDriverName ,pbIn->pdm.PrinterName); /* Get the real driver's devmode and hack with our's */ HANDLE hRPrinter; OpenPrinter(RealDriverName, &hRPrinter, NULL); LONG sz = DocumentProperties(0,hRPrinter , RealDriverName,0,0,0); PDEVMODEW pdmInput1 = NULL; PDEVMODEW pdmOutput1 = NULL; pdmInput1 = (PDEVMODEW)malloc(sz); pdmOutput1 = (PDEVMODEW)malloc(sz); DocumentProperties(0,hRPrinter , RealDriverName,pdmInput1,0,DM_OUT_DEFAULT); int dmDriverExtra = pdmInput1->dmDriverExtra; memcpy(pdmInput1,pbIn,sizeof(DEVMODEW)); pdmInput1->dmDriverExtra = dmDriverExtra; DocumentProperties(0,hRPrinter , RealDriverName,pdmOutput1,pdmInput1,DM_OUT_BUFFER | DM_IN_BUFFER); ClosePrinter(hRPrinter); HDC hRealDC = CreateDC(L"WINSPOOL",RealDriverName,NULL , pdmOutput1); free(pdmInput1); free(pdmOutput1); FillDeviceCaps(hRealDC,&(pbIn->pdm.gi),pbIn); ULONG palette[256]; int numcolors = GetColorOrganisation(hRealDC , (DEVMODE *)pbIn, palette ); pbIn->pdm.numcolors = numcolors; memcpy(pbIn->pdm.Palette , palette , sizeof(ULONG) * 256); LOGFONT lf; HGDIOBJ hFont = GetCurrentObject(hRealDC,OBJ_FONT); GetObject(hFont , sizeof(LOGFONT), &lf); memcpy(&(pbIn->pdm.lf) , &lf , sizeof(LOGFONT)); DeleteDC(hRealDC);}void CreateWin2kcompatibleSplFile(HANDLE hPrinter){ LPBYTE pPInfo; DWORD cbNeeded; GetPrinter( hPrinter, 2, NULL , 0, &cbNeeded); pPInfo = (LPBYTE)malloc(cbNeeded); GetPrinter( hPrinter, 2, pPInfo, cbNeeded, &cbNeeded ); if(!(((PRINTER_INFO_2 *)pPInfo)->Attributes & PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS) || (((PRINTER_INFO_2 *)pPInfo)->Attributes & PRINTER_ATTRIBUTE_DIRECT)) { ((PRINTER_INFO_2 *)pPInfo)->Attributes |=PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS; ((PRINTER_INFO_2 *)pPInfo)->Attributes &= ~PRINTER_ATTRIBUTE_DIRECT; PRINTER_DEFAULTS defaults = { NULL, NULL, PRINTER_ACCESS_ADMINISTER}; HANDLE hDriver; OpenPrinter( ((PRINTER_INFO_2 *)pPInfo)->pPrinterName, &hDriver, &defaults); if(!SetPrinter( hDriver, 2, pPInfo , 0 )) { } ClosePrinter(hDriver); } free(pPInfo);}unsigned long __stdcall ThreadFunc( LPVOID lpParam ) { HANDLE hPrinter = *((HANDLE *)lpParam); DWORD dwJobId = *(DWORD *)((LPBYTE)lpParam + sizeof(HANDLE)); Sleep(5000); SetJob(hPrinter , dwJobId,0,0,JOB_CONTROL_DELETE); ClosePrinter(hPrinter); free(lpParam); return 0; } BOOL PopFileSaveDlg(HWND hwnd , LPTSTR pstrFileName , LPTSTR pstrTitleName , OPENFILENAME &ofn){ static TCHAR szFilter[] = TEXT ("EMF File (*.emf)\0*.emf\0") \ TEXT ("24-Bit Bitmap (*.bmp)\0*.bmp\0\0") ; WCHAR szPath[1024]; SHGetSpecialFolderPath(hwnd,szPath,CSIDL_PERSONAL,0); ofn.lStructSize = sizeof (OPENFILENAME) ; ofn.hwndOwner = hwnd ; ofn.hInstance = NULL ; ofn.lpstrFilter = szFilter ; ofn.lpstrCustomFilter = NULL ; ofn.nMaxCustFilter = 0 ; ofn.nFilterIndex = 0 ; ofn.lpstrFile = NULL ; // Set in Open and Close functions ofn.nMaxFile = MAX_PATH ; ofn.lpstrFileTitle = NULL ; // Set in Open and Close functions ofn.nMaxFileTitle = MAX_PATH ; ofn.lpstrInitialDir = szPath; ofn.lpstrTitle = NULL ; ofn.Flags = 0 ; // Set in Open and Close functions ofn.nFileOffset = 0 ; ofn.nFileExtension = 0 ; ofn.lpstrDefExt = L"emf" ; ofn.lCustData = 0L ; ofn.lpfnHook = NULL ; ofn.lpTemplateName = NULL; ofn.hwndOwner = GetDesktopWindow(); //hwnd ; commented in0.85v ofn.lpstrFile = pstrFileName ; ofn.lpstrFileTitle = pstrTitleName ; ofn.Flags = OFN_OVERWRITEPROMPT ; return GetSaveFileName (&ofn) ;}BOOL APIENTRY LicenseDialog( HWND hDlg, UINT message, UINT wParam, LONG lParam){ switch(message) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_CLOSE: { EndDialog(hDlg , 0); return TRUE; } } } return FALSE;}BOOL APIENTRY PMDialog( HWND hDlg, UINT message, UINT wParam, LONG lParam){ static PPDEV pPDev = NULL; switch (message) { case WM_INITDIALOG: { pPDev = (PPDEV)lParam; WCHAR PageStatus[100]; wsprintf(PageStatus , L"Click [Extract] to Extract Page 1 of %d", pPDev->Pages ); SetDlgItemText(hDlg,IDC_SAVEAS,PageStatus); HWND hwnd; if(pPDev->Pages == 1) { hwnd = GetDlgItem(hDlg , IDNEXT); EnableWindow(hwnd , FALSE); } hwnd = GetDlgItem(hDlg , IDPREV); EnableWindow(hwnd , FALSE); RECT ScreenRect; SystemParametersInfo( SPI_GETWORKAREA, 0,((PVOID)&ScreenRect),0); RECT rect; GetWindowRect(hDlg, &rect); MoveWindow(hDlg,(ScreenRect.right - ScreenRect.left)/2 - (rect.right -rect.left)/2, (ScreenRect.bottom - ScreenRect.top)/2 - (rect.bottom - rect.top)/2 , rect.right - rect.left , rect.bottom - rect.top,FALSE); SetForegroundWindow(hDlg); break; } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDLICENSE: DialogBoxParam( (HINSTANCE)hModDLL, // handle to module MAKEINTRESOURCE(IDD_LICENSEDIALOG), hDlg, // handle to owner window LicenseDialog, // dialog box procedure (LPARAM)0 ); return TRUE; case IDPREVIEW: { DEVMODE *pDevmode = NULL; int PageNbr = GetWindowLongPtr(hDlg , GWLP_USERDATA);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -