📄 prutils.cpp
字号:
BOOL FillListWithInstalledPrinters(HWND hwndList, BOOL bAllowPrintResizer) { BOOL bRetValue = ::FillControlWithInstalledPrinters(hwndList, bAllowPrintResizer, LB_RESETCONTENT, LB_ADDSTRING); return bRetValue;}BOOL FindStringInCombo(OUT PDWORD pdwFoundIndex, IN LPCTSTR lptstrFind, IN HWND hwndCtrl) { BOOL b = FindStringInControl(pdwFoundIndex, lptstrFind, hwndCtrl, CB_GETCOUNT, CB_GETLBTEXT, CB_GETLBTEXTLEN, CB_ERR); return b;}BOOL GetComboCurSelLBText(OUT ItemBuffer& buff, IN HWND hwndCombo) { BOOL bRetValue = FALSE; LRESULT lresIndex = ::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0); if (lresIndex != CB_ERR) { bRetValue = ::GetComboLBText(buff, (WPARAM) lresIndex, hwndCombo); } return bRetValue;}BOOL GetComboLBText(OUT ItemBuffer& buff, IN WPARAM itemIndex, IN HWND hwndCombo) { BOOL b = ::GetItemStringFromControl(buff, itemIndex, hwndCombo, CB_GETLBTEXT, CB_GETLBTEXTLEN, CB_ERR); return b;}LPTSTR GetInstalledGPLRTFTextFileName(void) { LPTSTR lptstrRetValue = NULL; ::PDRIVER_INFO_3 pinfo = NULL; uint kDriver = 0; if (::CheckPrinterDriverInstalled(pinfo, kDriver, PRINTRESIZER_DRIVERNAME)) { lptstrRetValue = ::StringDuplicate(pinfo[kDriver].pDataFile); free(pinfo); } return lptstrRetValue;}LPTSTR GetPRErrorMessage(IN DWORD dwErr) { LPTSTR lptstr = NULL; if (dwErr & 0x2000) { ASSERTFAIL(); } else { lptstr = ::GetSystemErrorMessage(dwErr); } return lptstr;}LPTSTR GetPreviewAppFullNameAndFullTempFileName(IN HANDLE hPrinter, OUT LPTSTR lptstrTempFileName, IN DWORD dwcChBuff) { LPTSTR lptstr = NULL; if (::GetFullTempFileName(lptstrTempFileName, dwcChBuff)) { lptstr = ::GetPreviewAppFullFileName(hPrinter); } return lptstr;}LPTSTR GetPreviewAppFullFileName(IN HANDLE hPrinter) { LPTSTR lptstr = NULL; ::PDRIVER_INFO_3 pinfo = ::GetPrinterDriverInfo3(hPrinter); if (pinfo != NULL) { lptstr = ::GetPreviewAppFullFileNameInInstalledDriverDirectory(pinfo->pDependentFiles); free(pinfo); } return lptstr;}#if 0LPTSTR GetPreviewAppFullFileName(void) { LPTSTR lptstr = NULL; DWORD dwcChNeeded = ::GetPreviewAppFullFileName(NULL, 0); if (dwcChNeeded != 0) { lptstr = (LPTSTR) ::malloc(dwcChNeeded * sizeof(TCHAR)); if (lptstr != NULL) { if (::GetPreviewAppFullFileName(lptstr, dwcChNeeded) == 0) { free(lptstr); lptstr = NULL; } } } return lptstr;}DWORD GetPreviewAppFullFileName(LPTSTR lptstrFileName, DWORD dwcChBuff) { // FIX - DEBUG SHOULD STORE THIS IN A REGISTRY VALUE THAT IS SET AT INSTALL TIME LPTSTR lptstr = TEXT("C:\\WINDDK\\3790.1830\\src\\print\\PrintResizer\\prpreview\\objchk_w2k_x86\\i386\\prpreview.exe"); DWORD dwcChNeeded = ::lstrlen(lptstr) + 1; DWORD dwcChRetValue = dwcChNeeded; if (dwcChBuff >= dwcChNeeded) { // AS REMINDER TO SET ERROR CODES IN FINAL VERSION if (::StringCchCopy(lptstrFileName, dwcChBuff, lptstr) != S_OK) { dwcChRetValue = 0; } } return dwcChRetValue;}#endif// dwcChBuff MUST BE AT LEAST MAX_PATH + 1 BOOL GetFullTempFileName(LPTSTR lptstrTempFileName, DWORD dwcChBuff) { ASSERT(dwcChBuff >= MAX_PATH+1); TCHAR atstrTempPath[MAX_TEMP_PATH_CCH+1]; ::MyGetTempPath(atstrTempPath, ARRCOUNT(atstrTempPath)); BOOL bSuccess = ::GetTempFileName(atstrTempPath, NULL, 0, lptstrTempFileName) != 0; return bSuccess;}BOOL IsScreenResolutionOK(void) { BOOL bRetValue = FALSE; HDC hdc = ::GetDC(NULL); if (hdc != NULL) { try { SIZE sz = { ::GetDeviceCaps(hdc, HORZRES), ::GetDeviceCaps(hdc, VERTRES) }; if (sz.cx >= PRINTRESIZER_MINSCREENRES_CX && sz.cy >= PRINTRESIZER_MINSCREENRES_CY) { bRetValue = TRUE; } ::ReleaseDC(NULL, hdc); } catch (...) { ::ReleaseDC(NULL, hdc); throw; } } return bRetValue;}BOOL IsPrintResizer(IN const ::PRINTER_INFO_2& info2) { BOOL b = ( ::lstrcmpi(info2.pDriverName, PRINTRESIZER_DRIVERNAME) == 0 ); return b;}// lptstrPath BUFFER HAVE SPACE FOR MAX_TEMP_PATH_CCH+1 TCHARSvoid MyGetTempPath(LPTSTR lptstrPath, DWORD dwcChBuff) { ASSERT(dwcChBuff >= 3); DWORD dwcChLength = ::GetTempPath(dwcChBuff, lptstrPath); // LENGTH IS STRING LENGTH if (dwcChLength == 0 || dwcChLength > dwcChBuff-1) { ::StringCchCopy(lptstrPath, dwcChBuff, FALLBACK_TEMP_PATH); }}void NotificationMessage(IN ::PrintResizerComponent comp, IN HWND hwndParent, IN LPCTSTR lptstrMessage) { tstring tstrCaption; ::ComposeDialogTitle(comp, tstrCaption, TEXT("Please Read")); ::MessageBox(hwndParent, lptstrMessage, tstrCaption.c_str(), MB_OK | MB_ICONINFORMATION | MB_DEFBUTTON1);}TCHAR const gtcParameterSep = ',';BOOL ParsePrintProcessorParameter(OUT PrintProcessorParameter& ppp, IN LPCWSTR lpwstrParameter) { BOOL bRetValue = FALSE; if (lpwstrParameter != NULL) { LPCWSTR lpwstrSep = wcschr(lpwstrParameter, gtcParameterSep); if (lpwstrSep != NULL) { DWORD dwcChCopy = (DWORD) (lpwstrSep - lpwstrParameter)+1; // +1 FOR NULL TERMINATOR if (dwcChCopy < ARRCOUNT(ppp.atstrFullTempFileName)) { // TRUNCATED COPY -- ACTUALLY COPIES dwcChCopy-1 TCHAR'S AND THEN NULL TERMINATES StringCchCopy(ppp.atstrFullTempFileName, dwcChCopy, lpwstrParameter); ulong ul; if (::swscanf(lpwstrSep+1, L"%ul", &ul) == 1) { ppp.hwndPreviewApp = (HWND) ul; bRetValue = TRUE; } } } } return bRetValue;}DWORD WritePrintProcessorParameter(OUT LPWSTR lpwstrParameter, IN DWORD dwcChBuff, IN const PrintProcessorParameter& ppp) { DWORD dwRetValue = 0; WCHAR awstrBuff[WINDOWHANDLE_MAX_CCH+1]; if ( ::StringCchPrintf(awstrBuff, ARRCOUNT(awstrBuff), TEXT("%ul"), (ulong) ppp.hwndPreviewApp) == S_OK ) { DWORD dwcChNeeded = lstrlen(awstrBuff) + lstrlen(ppp.atstrFullTempFileName) + 2; // +2 FOR COMMA SEPARATOR AND NULL TERMINATOR dwRetValue = dwcChNeeded; if (dwcChBuff >= dwcChNeeded) { if (::StringCchPrintf(lpwstrParameter, dwcChBuff, TEXT("%ls,%lu"), ppp.atstrFullTempFileName, (ulong) ppp.hwndPreviewApp) != S_OK) { dwRetValue = 0; } } } return dwRetValue;}// **************************************************************************************************// ** MODULE PRIVATE ROUTINES *********************************************************************// **************************************************************************************************static BOOL FillControlWithInstalledPrinters( HWND hwndControl, BOOL bAllowPrintResizer, IN UINT msgResetContent, IN UINT msgAddString) { BOOL bRetValue = FALSE; DWORD dwcCount = 0; PPRINTER_INFO_2 pinfo2 = NULL; ::SendMessage(hwndControl, msgResetContent, 0, 0); pinfo2 = ::GetInstalledPrintersInfo2(&dwcCount); if (pinfo2 != NULL) { DWORD k; for(k = 0; k < dwcCount; ++k) { if (bAllowPrintResizer || !::IsPrintResizer(pinfo2[k])) { ::SendMessage(hwndControl, msgAddString, 0, (LPARAM) pinfo2[k].pPrinterName); } } free(pinfo2); bRetValue = TRUE; } SHOULD(bRetValue); return bRetValue;}// I NEED CASE-SENSITIVE SEARCH BECAUSE PRINTER NAMES ARE CASE SENSITIVEstatic BOOL FindStringInControl( OUT PDWORD pdwFoundIndex, IN LPCTSTR lptstrFind, IN HWND hwndCtrl, IN UINT msgGetCount, IN UINT msgGetString, IN UINT msgGetStringLen, IN LRESULT lresError ) { BOOL bRetValue = FALSE; LRESULT lres; lres = SendMessage(hwndCtrl, msgGetCount, 0, 0); if (lres != lresError) { ItemBuffer buffString(64, sizeof(TCHAR)); DWORD dwcCount = (DWORD) lres; DWORD k; for(k = 0; k < dwcCount && !bRetValue; ++k) { if (GetItemStringFromControl(buffString, (WPARAM) k, hwndCtrl, msgGetString, msgGetStringLen, lresError)) { if (lstrcmp((LPTSTR) buffString.GetPtr(), lptstrFind) == 0) { *pdwFoundIndex = k; bRetValue = TRUE; } } } } return bRetValue;}static BOOL GetItemStringFromControl( OUT ItemBuffer& buff, IN WPARAM itemIndex, IN HWND hwndCtrl, IN UINT msgGetString, IN UINT msgGetStringLen, IN LRESULT lresError) { BOOL bRetValue = FALSE; LRESULT lres = SendMessage(hwndCtrl, msgGetStringLen, itemIndex, 0); if (lres != lresError) { DWORD dwcStringLen = (DWORD) lres; buff.RequireMinCount(dwcStringLen+1); lres = SendMessage(hwndCtrl, msgGetString, itemIndex, (LPARAM) buff.GetPtr()); if (lres != lresError) { bRetValue = TRUE; } } return bRetValue;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -