// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "ABCDemo.h" #include "ABCDoc.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CABCApp theApp; ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString) ON_WM_KEYDOWN() ON_WM_CLOSE() ON_COMMAND(ID_BORDER, OnBorder) ON_UPDATE_COMMAND_UI(ID_BORDER, OnUpdateBorder) ON_COMMAND(ID_COMBINE, OnCombine) ON_UPDATE_COMMAND_UI(ID_COMBINE, OnUpdateCombine) ON_COMMAND(ID_ENHANCED, OnEnhanced) ON_UPDATE_COMMAND_UI(ID_ENHANCED, OnUpdateEnhanced) ON_COMMAND(ID_FAST_MODIFIED_1, OnFastModified1) ON_UPDATE_COMMAND_UI(ID_FAST_MODIFIED_1, OnUpdateFastModified1) ON_COMMAND(ID_FAST_MODIFIED_2, OnFastModified2) ON_UPDATE_COMMAND_UI(ID_FAST_MODIFIED_2, OnUpdateFastModified2) ON_COMMAND(ID_FAST_MODIFIED_3, OnFastModified3) ON_UPDATE_COMMAND_UI(ID_FAST_MODIFIED_3, OnUpdateFastModified3) ON_COMMAND(ID_LOSSLESS, OnLossless) ON_UPDATE_COMMAND_UI(ID_LOSSLESS, OnUpdateLossless) ON_COMMAND(ID_MODIFIED_1, OnModified1) ON_UPDATE_COMMAND_UI(ID_MODIFIED_1, OnUpdateModified1) ON_COMMAND(ID_MODIFIED_2, OnModified2) ON_UPDATE_COMMAND_UI(ID_MODIFIED_2, OnUpdateModified2) ON_COMMAND(ID_MODIFIED_3, OnModified3) ON_UPDATE_COMMAND_UI(ID_MODIFIED_3, OnUpdateModified3) ON_COMMAND(ID_VIRTUALLOSSLESS, OnVirtuallossless) ON_UPDATE_COMMAND_UI(ID_VIRTUALLOSSLESS, OnUpdateVirtuallossless) ON_COMMAND(ID_LOSSLESS_FAST, OnLosslessFast) ON_UPDATE_COMMAND_UI(ID_LOSSLESS_FAST, OnUpdateLosslessFast) ON_COMMAND(ID_LOSSY_FAST, OnLossyFast) ON_UPDATE_COMMAND_UI(ID_LOSSY_FAST, OnUpdateLossyFast) //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_QUALITY, ID_PAGESAVED, ID_IMAGESIZE, ID_IMAGEBPP, ID_IMAGEMEM, ID_IMAGEDISK }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } UINT nID; UINT nStyles; int cxWidth; m_wndStatusBar.GetPaneInfo(0, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(0, nID, nStyles, cxWidth *(1/2)); m_wndStatusBar.GetPaneInfo(1, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(1, nID, nStyles, 100); m_wndStatusBar.GetPaneInfo(2, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(2, nID, nStyles, 200); m_wndStatusBar.GetPaneInfo(3, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(3, nID, nStyles, 75); m_wndStatusBar.GetPaneInfo(4, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(4, nID, nStyles, 35); m_wndStatusBar.GetPaneInfo(5, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(5, nID, nStyles, 90); m_wndStatusBar.GetPaneInfo(6, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(6, nID, nStyles, 90); // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CMDIFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CMDIFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CMDIFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers /*--------------------------------------------------------------------------+ | Function :OnSetMessageString | Desc :On Set Message String | Return :LRESULT | Notes : +--------------------------------------------------------------------------*/ LRESULT CMainFrame::OnSetMessageString(WPARAM wParam, LPARAM lParam) { UINT nIDLast = m_nIDLastMessage; m_nFlags &= ~WF_NOPOPMSG; CWnd* pMessageBar = GetMessageBar(); CStatusBar* pStatusBar = (CStatusBar*)pMessageBar; if (pStatusBar) { LPCTSTR lpsz = NULL; CString strMessage; // set the message bar text if (lParam != 0) { ASSERT(wParam == 0); // can't have both an ID and a string lpsz = (LPCTSTR)lParam; // set an explicit string } else if (wParam != 0) { // get message associated with the ID indicated by wParam GetMessageString(wParam, strMessage); lpsz = strMessage; } pStatusBar->SetWindowText(lpsz); } m_nIDLastMessage = (UINT)wParam; // new ID (or 0) m_nIDTracking = (UINT)wParam; // so F1 on toolbar buttons work return nIDLast; } /*--------------------------------------------------------------------------+ | Function :RedrawChildrenCB | Desc :Redraw Children Call Back | Return :bool | Notes : +--------------------------------------------------------------------------*/ BOOL CALLBACK RedrawChildrenCB(HWND hWnd, LPARAM lParam) { RedrawWindow(hWnd,0,0,RDW_INVALIDATE|RDW_ALLCHILDREN|(LOWORD(lParam) ? RDW_ERASE:0)); return(TRUE); } /*--------------------------------------------------------------------------+ | Function :RedrawChildren | Desc :Redraw Children | Return :void | Notes : +--------------------------------------------------------------------------*/ void CMainFrame::RedrawChildren(BOOL bErase) { EnumChildWindows(this->m_hWnd, (WNDENUMPROC)RedrawChildrenCB, bErase); return; } void CMainFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { switch(nChar) { case VK_ESCAPE: theApp.m_bKillProgress = TRUE; break; } CMDIFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags); } void CMainFrame::OnClose() { CMDIFrameWnd::OnClose(); } void CMainFrame::OnUpdateLossless(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_LOSSLESS); } void CMainFrame::OnUpdateBorder(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_REMOVEBORDER); } void CMainFrame::OnUpdateCombine(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_bCombine == TRUE); } void CMainFrame::OnCombine() { theApp.m_bCombine = !theApp.m_bCombine; } void CMainFrame::OnLossless() { theApp.m_Quality = QFACTOR_ABCQ_LOSSLESS; theApp.m_szQuality = TEXT("Lossless"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnBorder() { theApp.m_Quality = QFACTOR_ABCQ_REMOVEBORDER; theApp.m_szQuality = TEXT("RemoveBorder"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnVirtuallossless() { theApp.m_Quality = QFACTOR_ABCQ_VIRTUALLOSSLESS; theApp.m_szQuality = TEXT("VirtualLossless"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnUpdateVirtuallossless(CCmdUI* pCmdUI) { pCmdUI->Enable(TRUE); pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_VIRTUALLOSSLESS); } void CMainFrame::OnEnhanced() { theApp.m_Quality = QFACTOR_ABCQ_ENHANCE; theApp.m_szQuality = TEXT("Enhanced"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnUpdateEnhanced(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_ENHANCE); } void CMainFrame::OnModified1() { theApp.m_Quality = QFACTOR_ABCQ_MODIFIED1; theApp.m_szQuality = TEXT("Modified_1"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnUpdateModified1(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_MODIFIED1); } void CMainFrame::OnFastModified1() { theApp.m_Quality = QFACTOR_ABCQ_MODIFIED1_FAST; theApp.m_szQuality = TEXT("FastModified_1"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnUpdateFastModified1(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_MODIFIED1_FAST); } void CMainFrame::OnModified2() { theApp.m_Quality = QFACTOR_ABCQ_MODIFIED2; theApp.m_szQuality = TEXT("Modified_2"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnUpdateModified2(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_MODIFIED2); } void CMainFrame::OnFastModified2() { theApp.m_Quality = QFACTOR_ABCQ_MODIFIED2_FAST; theApp.m_szQuality = TEXT("FastModified_2"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnUpdateFastModified2(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_MODIFIED2_FAST); } void CMainFrame::OnModified3() { theApp.m_Quality = QFACTOR_ABCQ_MODIFIED3; theApp.m_szQuality = TEXT("Modified_3"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnUpdateModified3(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_MODIFIED3); } void CMainFrame::OnFastModified3() { theApp.m_Quality = QFACTOR_ABCQ_MODIFIED3_FAST; theApp.m_szQuality = TEXT("FastModified_3"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnUpdateFastModified3(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_MODIFIED3_FAST); } void CMainFrame::PreviewCompress() { theApp.ClosePreviewDocument(); CString csOutFile = PREVIEW_TEMP_FILE_NAME; CString csOutFileG4 = PREVIEW_TEMP_FILE_NAME_G4; int nRet = 0; ILEADRaster * pRaster = NULL; CABCDoc *pCompressDoc = NULL; HRESULT hr = CoCreateInstance(CLSID_LEADRaster, NULL, CLSCTX_ALL, IID_ILEADRaster, (void**)&pRaster); if (FAILED(hr)) return; HCURSOR hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT)); pRaster->put_EnableMethodErrors(FALSE); nRet = theApp.m_pRasterIO->Load(pRaster, (LPCTSTR)theApp.m_szOpenedFileName, 0, theApp.m_nPageNumber, 1); nRet = theApp.m_pRasterIO->Save(pRaster, (LPCTSTR)csOutFile, FILE_ABC, 1, (QFactorConstants)theApp.m_Quality, 0); theApp.DisplayLEADError(nRet); nRet = theApp.m_pRasterIO->Save(pRaster, (LPCTSTR)csOutFileG4, FILE_CCITT_GROUP4, 1, (QFactorConstants)theApp.m_Quality, 0); theApp.DisplayLEADError(nRet); SetCursor (hCursor); pCompressDoc = (CABCDoc*)theApp.m_pDocManager->OpenDocumentFile(csOutFile); if (pCompressDoc) { CString csTitle; csTitle.Format(TEXT("%s ( %s ) "), PREVIEWSTRING, theApp.m_szQuality); pCompressDoc->SetTitle(csTitle); pCompressDoc->m_bCompressed = TRUE; } /// this is to chose vertical or horizontal tiling RECT rectClient; GetClientRect(&rectClient); int cleintWidth = rectClient.right; int clientHeight = rectClient.bottom; int imageWidth = (int)pRaster->BitmapWidth; int imageHeight = (int)pRaster->BitmapHeight; float cxV = (imageWidth + imageWidth) / (float)cleintWidth; float cyV = imageHeight / (float)clientHeight; float cxH = imageWidth / (float)cleintWidth; float cyH = (imageHeight + imageHeight) / (float)clientHeight; float cx = min( cxH, cxV ); float cy = min( cyH, cyV ); if (cx >= cy) MDITile(MDITILE_HORIZONTAL); else MDITile(MDITILE_VERTICAL); // end of chose vertical or horizontal tiling theApp.FitImagesToWindows(); // this part of the code copmare the size of one compressed fil HANDLE hF1; DWORD dwSizeF1, dwSizeF2 ; hF1 = CreateFile(csOutFileG4, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (INVALID_HANDLE_VALUE == hF1) AfxMessageBox(csOutFile, MB_OK); dwSizeF1 = GetFileSize(hF1, NULL); if (dwSizeF1 == INVALID_FILE_SIZE) AfxMessageBox(csOutFile, MB_OK); CloseHandle(hF1); hF1 = CreateFile(csOutFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (INVALID_HANDLE_VALUE == hF1) AfxMessageBox(csOutFile, MB_OK); dwSizeF2 = GetFileSize(hF1, NULL); if (dwSizeF2 == INVALID_FILE_SIZE) AfxMessageBox(csOutFile, MB_OK); CloseHandle(hF1); CString csSizeMessage; float fR = ((float)dwSizeF1 / (float)dwSizeF2) * 100.0F; csSizeMessage.Format(TEXT("CCITT G4: %3d,%03d bytes \nLEAD ABC: %3d,%03d bytes \n %6.3f %% Improvement "), dwSizeF1/1000, dwSizeF1%1000, dwSizeF2/1000, dwSizeF2%1000, fR); AfxMessageBox(csSizeMessage, MB_OK); pRaster->Free(); pRaster->Release(); } void CMainFrame::OnLosslessFast() { theApp.m_Quality = QFACTOR_ABCQ_LOSSLESS_FAST; theApp.m_szQuality = TEXT("Fast LossLess"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnUpdateLosslessFast(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_LOSSLESS_FAST ); } void CMainFrame::OnLossyFast() { theApp.m_Quality = QFACTOR_ABCQ_LOSSY_FAST; theApp.m_szQuality = TEXT("Fast Lossy"); PreviewCompress(); m_wndStatusBar.SetPaneText(1, theApp.m_szQuality, TRUE); RedrawChildren(FALSE); } void CMainFrame::OnUpdateLossyFast(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_Quality == QFACTOR_ABCQ_LOSSY_FAST ); }