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

📄 prutils.cpp

📁 虚拟打印机
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*  * * prutils.cpp * *   Copyright (C) 2006 Michael H. Overlin   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 poster_printer@yahoo.com */#include "prutils.h"#include "buffer.h"#include "dependentfilesparam.h"#include "spoolutils.h"#include "types.h"#include "utils.h"#include <strsafe.h>#include <shlobj.h>#include <shellapi.h>// FROM DOCS, MAX ALLOWED LENGTH OF PATH SUPPLIED TO API GetTempFileName#define MAX_TEMP_PATH_CCH				(MAX_PATH - 14)// FALL BACK TO CURRENT DIRECTORY IN CASE THAT API FAILS, OR WANTS TO RETURN A PATH LENGTH LONGER// THAN THE ALLOWS MAX_TEMP_PATH_CCH#define FALLBACK_TEMP_PATH				TEXT(".\\")// CAN BE USED WITH LIST BOXES OR COMBO BOXES BY FILLING IN THE MSG AND RESULT CODE PARAMSBOOL FillControlWithInstalledPrinters(	HWND hwndControl, 	BOOL bAllowPrintResizer,	IN UINT msgResetContent,	IN UINT msgAddString) ;// CAN BE USED WITH LIST BOXES OR COMBO BOXES BY FILLING IN THE MSG AND RESULT CODE PARAMSBOOL FindStringInControl(	OUT PDWORD pdwFoundIndex,	IN LPCTSTR lptstrFind,	IN HWND hwndCtrl, 	IN UINT msgGetCount,	IN UINT msgGetString,	IN UINT msgGetStringLen,	IN LRESULT lresError	) ;// CAN BE USED WITH LIST BOXES OR COMBO BOXES BY FILLING IN THE MSG AND RESULT CODE PARAMSBOOL GetItemStringFromControl(	OUT ItemBuffer& buff,	IN WPARAM itemIndex,	IN HWND hwndCtrl, 	IN UINT msgGetString,	IN UINT msgGetStringLen,	IN LRESULT lresError	) ;// **************************************************************************************************// **  MODULE PUBLIC ROUTINES  **********************************************************************// **************************************************************************************************BOOL CheckIsPrintResizer(OUT BOOL& bIsPrintResizer, IN LPCTSTR lptstrPrinterName) {	BOOL bRetValue = FALSE;	::PPRINTER_INFO_2 pinfo2 = ::GetPrinterInfo2(lptstrPrinterName);	if (pinfo2 != NULL) {		bIsPrintResizer = ::IsPrintResizer(*pinfo2);		bRetValue = TRUE;		free(pinfo2);	}	return bRetValue;}BOOL CheckPrinterDriverInstalled(OUT ::PDRIVER_INFO_3& out_pinfoDrivers, OUT uint& out_kDriver, 								 IN LPCTSTR lptstrDriverName) {	BOOL bRetValue = FALSE;	DWORD dwcPrinterDrivers;	::PDRIVER_INFO_3 pinfoDrivers = ::GetInstalledPrinterDrivers(dwcPrinterDrivers);	if (pinfoDrivers != NULL) {		BOOL bFound = FALSE;		uint kDriver;		for(kDriver = 0; kDriver < dwcPrinterDrivers; ++kDriver) {			if (::lstrcmpi(pinfoDrivers[kDriver].pName, lptstrDriverName) == 0) {				bFound = TRUE;				break;			}		}		if (bFound) {			out_kDriver = kDriver;			out_pinfoDrivers = pinfoDrivers;		} else {			free(pinfoDrivers);			out_pinfoDrivers = NULL;		}		bRetValue = TRUE;	}	return bRetValue;}// CHOOSES DEFAULT PRINTER IF THERE IS A DEFAULT WHICH DOESN'T USE THIS DRIVER// OTHERWISE CHOOSES FIRST FROM ENUMERATION WHICH DOESNT USE THIS DRIVER// IF NONE SATISFIES THIS, SETS TO STRING OF 0 LENGTH#if 0void ChooseTargetPrinterNameWithoutUserInput(OUT LPTSTR lptstr) {	DWORD dwcBuff = 0;	DWORD dwcEnum = 0;	PPRINTER_INFO_2 pinfo = NULL;	BOOL bDefaultIsThis = FALSE;	LPTSTR lptstrNameNotThis = NULL;	LPTSTR lptstrNameIsThis = NULL;	TCHAR atstrDefPrinterName[TARGETPRINTERNAME_MAX];	WORD k;	dwcBuff = ARRCOUNT(atstrDefPrinterName);	if (!GetDefaultPrinter(atstrDefPrinterName, &dwcBuff)) {		*atstrDefPrinterName = 0;	}	// NOTE/FIX IF RETURN IS NULL THIS IS AN ERROR,	// SHOULD INDICATE BY RETURNING A BOOL	pinfo = GetInstalledPrintersInfo2(&dwcEnum);	if (pinfo != NULL) {		// DETERMINE IF THE DEFAULT PRINTER HAS THIS DRIVER AS ITS DRIVER		// AND FIND A PRINTER WHICH DOES NOT HAVE THIS DRIVER AS ITS DRIVER		for(k = 0; k < dwcEnum; ++k) {			if (lstrcmp(pinfo[k].pPrinterName, atstrDefPrinterName) == 0) {				if (lstrcmp(pinfo[k].pDriverName, PRINTRESIZER_DRIVERNAME) == 0) {					bDefaultIsThis = TRUE;				}			}			if (lstrcmp(pinfo[k].pDriverName, PRINTRESIZER_DRIVERNAME) != 0) {				if (lptstrNameNotThis == NULL) {					lptstrNameNotThis = pinfo[k].pPrinterName;				}			} else if (lptstrNameIsThis == NULL) {				lptstrNameIsThis = pinfo[k].pPrinterName;			}		}	}	if (!bDefaultIsThis && lstrlen(atstrDefPrinterName) != 0) {		StringCchCopy(lptstr, TARGETPRINTERNAME_MAX, atstrDefPrinterName);	} else if (lptstrNameNotThis != NULL) {		StringCchCopy(lptstr, TARGETPRINTERNAME_MAX, lptstrNameNotThis);	// 6/23	//} else {	//	lptstr[0] = 0;	//}	} else if (lptstrNameIsThis != NULL) {		//lptstr[0] = 0;		StringCchCopy(lptstr, TARGETPRINTERNAME_MAX, lptstrNameIsThis);	} else {		lptstr[0] = 0;		ASSERTFAIL();	}	free(pinfo);}#elseLPTSTR ChooseTargetPrinterNameWithoutUserInput(void) {	LPTSTR lptstrRetValue = NULL;	LPTSTR lptstrNameNotThis = NULL;	LPTSTR lptstrNameIsThis = NULL;	BOOL bDefaultIsThis = FALSE;	LPTSTR lptstrDefaultPrinter = ::MyGetDefaultPrinter();	DWORD dwcEnum;	PPRINTER_INFO_2 pinfo = GetInstalledPrintersInfo2(&dwcEnum);	if (pinfo != NULL) {		// DETERMINE IF THE DEFAULT PRINTER HAS THIS DRIVER AS ITS DRIVER		// AND FIND A PRINTER WHICH DOES NOT HAVE THIS DRIVER AS ITS DRIVER		for(uint k = 0; k < dwcEnum; ++k) {			if (lptstrDefaultPrinter!= NULL && lstrcmp(pinfo[k].pPrinterName, lptstrDefaultPrinter) == 0) {				if (lstrcmp(pinfo[k].pDriverName, PRINTRESIZER_DRIVERNAME) == 0) {					bDefaultIsThis = TRUE;				}			}			if (lstrcmp(pinfo[k].pDriverName, PRINTRESIZER_DRIVERNAME) != 0) {				if (lptstrNameNotThis == NULL) {					lptstrNameNotThis = pinfo[k].pPrinterName;				}			} else if (lptstrNameIsThis == NULL) {				lptstrNameIsThis = pinfo[k].pPrinterName;			}		}	}	LPTSTR lptstrChoice = NULL;	if (lptstrDefaultPrinter != NULL && !bDefaultIsThis && lstrlen(lptstrDefaultPrinter) != 0) {		lptstrChoice = lptstrDefaultPrinter;	} else if (lptstrNameNotThis != NULL) {		lptstrChoice = lptstrNameNotThis;	} else if (lptstrNameIsThis != NULL) {		lptstrChoice = lptstrNameIsThis;	}	if (lptstrChoice != NULL) {		lptstrRetValue = ::StringDuplicate(lptstrChoice);	}	free(pinfo);	if (lptstrDefaultPrinter != NULL) {		free(lptstrDefaultPrinter);	}	return lptstrRetValue;}#endifvoid ComposeDialogTitle(IN ::PrintResizerComponent comp, OUT tstring& tstrTitle, IN LPCTSTR lptstrSubject) {	switch(comp) {	case ::PrintResizerComponents::ePreviewApp:		tstrTitle = PRINTRESIZER_APP_NAME;		break;	case ::PrintResizerComponents::eInstaller:		tstrTitle = PRINTRESIZER_INSTALLER_APP_NAME;		break;	case ::PrintResizerComponents::eUnInstaller:		tstrTitle = PRINTRESIZER_UNINSTALLER_STUB_APP_NAME;		break;	default:		ASSERTFAIL();		break;	}	if ( ::lstrlen(lptstrSubject) > 0 ) {		tstrTitle += TEXT(":  ");		tstrTitle += lptstrSubject;	}}BOOL ConfirmationMessage(IN ::PrintResizerComponent comp, IN HWND hwndParent, IN LPCTSTR lptstrMessage) {	tstring tstrTitle;	::ComposeDialogTitle(comp, tstrTitle, TEXT("Confirm"));	BOOL b = ::MessageBox(hwndParent, lptstrMessage, tstrTitle.c_str(), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) == IDYES; 	return b;}void ErrorMessage(IN ::PrintResizerComponent comp, IN HWND hwndParent, IN LPCTSTR lptstrMessage) {	tstring tstrCaption;	::ComposeDialogTitle(comp, tstrCaption, TEXT("Error"));	::MessageBox(hwndParent, lptstrMessage, tstrCaption.c_str(), MB_OK | MB_ICONERROR | MB_DEFBUTTON1);}void ErrorExit(IN ::PrintResizerComponent comp, IN HWND hwndParent, IN DWORD dwErrorCode) {	LPTSTR lptstr = ::GetPRErrorMessage(dwErrorCode);	::ErrorExit(comp, hwndParent, lptstr ? lptstr : TEXT(""));}void ErrorExit(IN ::PrintResizerComponent comp, IN HWND hwndParent, IN LPCTSTR lptstrMessage) {	tstring tstrMessage;	tstrMessage = TEXT("Must terminate due to error:  \n\n");	tstrMessage += lptstrMessage;	::ErrorMessage(comp, hwndParent, tstrMessage.c_str());	::ExitProcess(-1);}BOOL FillComboWithInstalledPrinters(HWND hwndCombo, BOOL bAllowPrintResizer) {	BOOL bRetValue = 		::FillControlWithInstalledPrinters(hwndCombo, bAllowPrintResizer, CB_RESETCONTENT, CB_ADDSTRING);	return bRetValue;}

⌨️ 快捷键说明

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