📄 previewdialog_filemenu.cpp
字号:
} return bRetValue;}void PreviewDialog::OnSaveOriginalAsBitmapCommand(void) { uint uiPage; if (this->ReadSelectedPage(uiPage)) { double dDPI; BOOL bSourceSelection; RECTD rdSave_Inches; tstring tstrFileName; if (this->GetSaveOriginalAsBitmapFileName(tstrFileName, bSourceSelection, rdSave_Inches, dDPI)) { if (! tstrFileName.empty()) { BOOL bUnexpectedError = FALSE; BOOL bWriteOK = FALSE; // DEBUG / FIX MAYBE WE SHOULD BE USING ONE OF OUR PRINTER DC'S AS A REF // IN CASE MONITOR IS IN A LOW COLOR MODE (DON'T THINK IT MATTERS FOR A 24BPP DIB SECTION) HDC hdcRef = ::GetDC(NULL); try { // GETDC / RELEASE DC SAFETY BLOCK if (hdcRef != NULL) { POINTD ptdLogPix = { dDPI, dDPI }; SIZED szdDib_Inches = { RW(rdSave_Inches), RH(rdSave_Inches) }; try { // MAKE SURE DIB GETS DELETED TRY BLOCK ::My24BPPDIBSection dib; HBITMAP hbmp = dib.Create(hdcRef, tstrFileName, szdDib_Inches, ptdLogPix); if (hbmp != NULL) { HDC hdcMem = ::CreateCompatibleDC(hdcRef); if (hdcMem != NULL) { ::ReleaseDC(NULL, hdcRef); hdcRef = NULL; //HENHMETAFILE hMeta = m_pDataSource->GetPageEMF(uiPage); if (m_hMetaForPage != NULL) { RECT rFrame_HM = { RoundToLong(m_ssResized.rdTotalImage_Inches.left * MICROMETERS_PER_INCH / 10), RoundToLong(m_ssResized.rdTotalImage_Inches.top * MICROMETERS_PER_INCH / 10), RoundToLong(m_ssResized.rdTotalImage_Inches.right * MICROMETERS_PER_INCH / 10), RoundToLong(m_ssResized.rdTotalImage_Inches.bottom * MICROMETERS_PER_INCH / 10) }; RECT rSave_HM = { RoundToLong(rdSave_Inches.left * MICROMETERS_PER_INCH / 10), RoundToLong(rdSave_Inches.top * MICROMETERS_PER_INCH / 10), RoundToLong(rdSave_Inches.right * MICROMETERS_PER_INCH / 10), RoundToLong(rdSave_Inches.bottom * MICROMETERS_PER_INCH / 10) }; SIZE szSave_HM = { RW(rSave_HM), RH(rSave_HM) }; { // HBITMAP SELECT BLOCK HBITMAP hbmpOld = (HBITMAP) ::SelectObject(hdcMem, hbmp); try { // SEEMS METAFILES ONLY DRAW THOSE PIXELS THAT ARE SET // ONES WE GET FROM PRINTERS ASSUME WHITE BACKGROUND // ONES FROM BITMAPS ARE OPAQUE (SET ALL THEIR PIXELS) SIZE sz_Pixels = dib.GetSize_Pixels(); ::PatBlt(hdcMem, 0, 0, sz_Pixels.cx, sz_Pixels.cy, WHITENESS); ::SetMapMode(hdcMem, MM_ANISOTROPIC); //::SetViewportOrgEx(hdcMem, 0, 0, NULL); //::SetViewportExtEx(hdcMem, szSave_HM.cx, szSave_HM.cy, NULL); ::SetViewportOrgEx(hdcMem, 0, 0, NULL); ::SetViewportExtEx(hdcMem, sz_Pixels.cx, sz_Pixels.cy, NULL); ::SetWindowOrgEx(hdcMem, rSave_HM.left, rSave_HM.top, NULL); ::SetWindowExtEx(hdcMem, szSave_HM.cx, szSave_HM.cy, NULL); ::PlayEnhMetaFile(hdcMem, m_hMetaForPage, &rFrame_HM); ::SelectObject(hdcMem, hbmpOld); // NOTE -- dib CAN'T BE CLOSED WHILE ITS BITMAP (hbmp) IS SELECTED INTO // A MEMORY DC dib.Close(); bWriteOK = TRUE; } catch(...) { ::SelectObject(hdcMem, hbmpOld); } } // HBITMAP SELECT BLOCK //::DeleteEnhMetaFile(hMeta); ::DeleteDC(hdcMem); hdcMem = NULL; } // if (hMeta != NULL) // IN CASE AN EXCEPTION CAUSED DELETION ABOVE TO BE SKIPPED if (hdcMem != NULL) { ::DeleteDC(hdcMem); } } // if (hdcMem != NULL) } // if (hbmp != NULL) } catch (...) { // MAKE SURE DIB GETS DELETED TRY BLOCK bUnexpectedError = TRUE; } // IN CASE AN EXCEPTION CAUSED RELEASE ABOVE TO BE SKIPPED if (hdcRef != NULL) { ::ReleaseDC(NULL, hdcRef); hdcRef = NULL; } } // if (hdcRef != NULL) } catch (...) { // GETDC / RELEASE DC SAFETY BLOCK bUnexpectedError = TRUE; if (hdcRef != NULL) { ::ReleaseDC(NULL, hdcRef); } } if (!bWriteOK) { try { ::DeleteFile(tstrFileName.c_str()); } catch (...) {} tstring tstrMessage = TEXT("Error writing file "); tstrMessage += tstrFileName; this->ErrorMessage(tstrMessage.c_str()); } else if (bUnexpectedError) { this->ErrorMessage(TEXT("An unexpected error occured, attempting to continue.")); } } // if ( ! tstrFileName.empty() ) } else { // if (this->GetSaveOriginalAsBitmapFileName(tstrFileName, bSourceSelection, rdSave_Inches, dDPI)) this->ErrorMessage(TEXT("Error initializing save")); } } else { // if (this->ReadSelectedPage(uiPage)) this->ErrorMessage(TEXT("No page is currently selected")); }} // void PreviewDialog::OnSaveOriginalAsBitmapCommand(void)void PreviewDialog::OnSavePosterCommand(void) { uint uiPage; if (this->ReadSelectedPage(uiPage)) { BOOL bSourceSelection; tstring tstrFileName; if (this->GetPoserSaveFileName(tstrFileName, bSourceSelection)) { if (! tstrFileName.empty()) { //HENHMETAFILE hMeta = m_pDataSource->GetPageEMF(uiPage); HENHMETAFILE hMeta = m_hMetaForPage; ::PageSpec psSave = m_psOriginal; //::SourceSpec ssSave = m_ssOriginal; ::SourceSpec ssSave = m_ssResized; //m_ssOriginal; if (bSourceSelection && hMeta != NULL) { HENHMETAFILE hMetaSource = hMeta; hMeta = NULL; TCHAR atstrBuff[MAX_LISTBOX_PAGES_CCH]; ::StringCchPrintf(atstrBuff, ARRCOUNT(atstrBuff), TEXT("%ld"), (DWORD) uiPage+1); tstring tstrTemp = m_pDataSource->GetJobName(); tstrTemp += TEXT( " selection from source page "); tstrTemp += atstrBuff; LPTSTR lptstrDescription = ::MyCatStringsString(TRUE, PRINTRESIZER_PACKAGE_NAME, tstrTemp.c_str(), NULL); if (lptstrDescription != NULL) { // DEBUG / FIX : MAYBE SHOULD USE OUR PRINTER TO GET REF DC (HIGHER RES THAN MONITOR) HDC hdcRef = ::GetDC(NULL); if (hdcRef != NULL) { try { SIZE szDestSelection_Pixels; hMeta = ::ExtractSelectionFromEnhMetafile( hMetaSource, m_ssResized.rdSelection_Inches, m_ssResized.rdTotalImage_Inches, hdcRef, NULL, lptstrDescription, szDestSelection_Pixels); if (hMeta != NULL) { // DEBUG / FIX ssSave.rdTotalImage_Inches = ssSave.rdSelection_Inches; //::GetEnhMetafileFrame_Inches(ssSave.rdTotalImage_Inches, hMeta); //ssSave.rdSelection_Inches = ssSave.rdTotalImage_Inches; ::ZeroMemory(&psSave, sizeof(psSave)); psSave.szlPhysicalPage.cx = szDestSelection_Pixels.cx; psSave.szlPhysicalPage.cy = szDestSelection_Pixels.cy; psSave.szlPrintable = psSave.szlPhysicalPage; psSave.szdPhysicalPage_Inches.cx = RW(ssSave.rdTotalImage_Inches); psSave.szdPhysicalPage_Inches.cy = RH(ssSave.rdTotalImage_Inches); } } catch( ... ) { ::ReleaseDC(NULL, hdcRef); } ::ReleaseDC(NULL, hdcRef); } } if (hMetaSource != NULL) { if (hMetaSource != m_hMetaForPage) { ::DeleteEnhMetaFile(hMetaSource); } } } // if (bSourceSelection && hMeta != NULL) if (hMeta != NULL) { PRPosterDataFileHandle h = PRPosterDataFile::TheirWritePosterDataFileHeader( tstrFileName.c_str(), this->m_pDataSource->GetJobName(), 1); if (h != NULL) { tstring tstrTargetPrinterName; this->ReadSelectedPrinter(tstrTargetPrinterName); PDEVMODE pdmTargetPrinter = this->m_pdmKeeper->GetDevMode(tstrTargetPrinterName); BOOL bEvenMargins = this->ReadEvenMargins(); BOOL bSuccess = PRPosterDataFile::TheirWritePosterDataFilePage( h, tstrTargetPrinterName, pdmTargetPrinter, this->ReadLandscape(), //! this->ReadNoCutGuidelines(), this->ReadAutoRotate(), bEvenMargins, //ssSave.rdSelection_Inches, psSave, ssSave, m_rsResized, hMeta ); // THIS WILL DELETE THE OUTPUT FILE IF bSuccess IS FALSE FROM ABOVE // OR IF CLOSING THE FILE FOR SOME REASON FAILS if ( ! PRPosterDataFile::TheirClosePosterDataFile(h, bSuccess) ) { bSuccess = FALSE; } if (!bSuccess) { this->ErrorMessage(TEXT("Error writing poster data")); } } else { this->ErrorMessage(TEXT("Error opening file for writing")); } if (hMeta != m_hMetaForPage) { ::DeleteEnhMetaFile(hMeta); } } else { this->ErrorMessage(TEXT("Error initializing save, could not get metafile data")); } } } else { this->ErrorMessage(TEXT("Error initializing save")); } } else { this->ErrorMessage(TEXT("No page is currently selected.")); }}// ****************************************************************************************// ** class FileNameCommDlgHookParams ***************************************************// ****************************************************************************************const LPTSTR FileNameCommDlgHookParams::their_lptstrPropName = TEXT("adslkj34197jsdlk32");BOOL FileNameCommDlgHookParams::ConfirmationMessage(LPCTSTR lptstrMessage, HWND hwndParent) { BOOL b = m_pd.ConfirmationMessage(lptstrMessage, hwndParent); return b;}void FileNameCommDlgHookParams::ErrorMessage(LPCTSTR lptstrMessage, HWND hwndParent) { m_pd.ErrorMessage(lptstrMessage, hwndParent); }FileNameCommDlgHookParams& FileNameCommDlgHookParams::TheirGetParams(HWND hDlg) { FileNameCommDlgHookParams& params = * (FileNameCommDlgHookParams *) ::GetProp(hDlg, FileNameCommDlgHookParams::their_lptstrPropName); return params;}// PRIVATEvoid FileNameCommDlgHookParams::TheirInstallParamsPtr(HWND hDlg, FileNameCommDlgHookParams& params) { ::SetProp(hDlg, FileNameCommDlgHookParams::their_lptstrPropName, (HANDLE) ¶ms);}// THIS IS THE BASE HOOK FOR ALL SAVE/OPEN COMMON DIALOG HOOKS// IT JUST ADDS THE EXTENSION TO THE USERS ENTERED FILE NAME WHEN THE FILTER CURRENTLY BEING USED// BY THE USER INDICATES A SPECIFIC EXTENSION TYPE (I.E. *.psr AS OPPOSED TO *.p?r)// IT CHECKS THAT THE FILE NAME ENTERED IS A VALID FILE NAME// IN THE CASE OF A SAVE AS DIALOG, IT ASKS THE USER TO OVERWRITE IF THE FILE ALREADY EXISTS// IN THE CASE OF AN OPEN DIALOG, IT GIVES AN ERROR MESSAGE IF THE FILE DOESN'T EXIST// OTHER HOOKS CHAIN IT IN BY ALLOWING IT TO DO ITS PROCESSING FIRSTUINT_PTR CALLBACK FileNameCommDlgHookParams::TheirGetFileNameCommDlgHook(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { UINT_PTR puiRetValue = NULL; switch(msg) { case WM_INITDIALOG: { LPOPENFILENAME lpOFN = (LPOPENFILENAME) lParam; ::FileNameCommDlgHookParams& params = * (::FileNameCommDlgHookParams * ) lpOFN->lCustData; ::FileNameCommDlgHookParams::TheirInstallParamsPtr(hDlg, params); params.m_bDlgInited = TRUE; puiRetValue = TRUE; } break; case WM_COMMAND: { break; } case WM_DESTROY: break; case WM_NOTIFY: { LPOFNOTIFY lpofn = (LPOFNOTIFY) lParam; ::FileNameCommDlgHookParams& params = ::FileNameCommDlgHookParams::TheirGetParams(hDlg); switch(lpofn->hdr.code) { case CDN_FILEOK: { LPTSTR lptstrFile = params.m_ofn.lpstrFile; LPTSTR lptstrTemp = params.m_ofn.lpstrCustomFilter; LPTSTR lptstrUserFilter = lptstrTemp + ::lstrlen(lptstrTemp) + 1; LPTSTR lptstrType = ::GetFileExt(lptstrUserFilter); if (lptstrType != NULL) { LPTSTR lptstr1 = ::wcschr(lptstrType, L'*'); LPTSTR lptstr2 = ::wcschr(lptstrType, L'?'); if (lptstr1 == NULL && lptstr2 == NULL) { if (! ::FileNameSpecifiesExt(lptstrFile) ) { StringCchCat(lptstrFile, params.m_ofn.nMaxFile, lptstrType); } } free(lptstrType); } if (! ::IsFileNameValid(lptstrFile) ) { tstring tstr = lptstrFile; tstr += TEXT(" is not a valid file name."); params.ErrorMessage(tstr.c_str(), hDlg); //params.m_pd.ErrorMessage(tstr.c_str(), hDlg); puiRetValue = TRUE; ::SetWindowLong(hDlg, DWL_MSGRESULT, TRUE); } else { BOOL bExists = ::FileExists(lptstrFile); switch(params.m_dbt) { case FileNameCommDlgHookParams::eSaveAs: if (bExists) { tstring tstr = lptstrFile; tstr += TEXT(" already exists.\nDo you want to overwrite it?"); //BOOL b = params.m_pd.ConfirmationMessage(tstr.c_str()); BOOL b = params.ConfirmationMessage(tstr.c_str(), hDlg); if (!b) { puiRetValue = TRUE; ::SetWindowLong(hDlg, DWL_MSGRESULT, TRUE); } } break; case FileNameCommDlgHookParams::eOpen: if (! bExists) { tstring tstr = lptstrFile; tstr += TEXT(" does not exist.\nPlease choose an existing file to open."); //params.m_pd.ErrorMessage(tstr.c_str(), hDlg); params.ErrorMessage(tstr.c_str(), hDlg); puiRetValue = TRUE; ::SetWindowLong(hDlg, DWL_MSGRESULT, TRUE); } break; default: ASSERTFAIL(); break; } } } break; default: break; } } break; default: break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -