// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "JPEG2000.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CJPEG2000App theApp; ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString) ON_WM_CREATE() ON_COMMAND(ID_FILE_BROWSEFORJPEGJPEG2000, OnFileBrowseforjpegjpeg2000) ON_UPDATE_COMMAND_UI(ID_FILE_BROWSEFORJPEGJPEG2000, OnUpdateFileBrowseforjpegjpeg2000) ON_WM_KEYDOWN() ON_WM_CLOSE() ON_COMMAND(ID_PREFERENCES_PAINTSCALING_BICUBIC, OnPreferencesPaintscalingBicubic) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_PAINTSCALING_BICUBIC, OnUpdatePreferencesPaintscalingBicubic) ON_COMMAND(ID_PREFERENCES_PAINTSCALING_NORMAL, OnPreferencesPaintscalingNormal) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_PAINTSCALING_NORMAL, OnUpdatePreferencesPaintscalingNormal) ON_COMMAND(ID_PREFERENCES_PAINTSCALING_RESAMPLE, OnPreferencesPaintscalingResample) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_PAINTSCALING_RESAMPLE, OnUpdatePreferencesPaintscalingResample) ON_COMMAND(ID_PREFERENCES_PROGRESSIVELOAD, OnPreferencesProgressiveload) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_PROGRESSIVELOAD, OnUpdatePreferencesProgressiveload) ON_WM_ACTIVATE() ON_UPDATE_COMMAND_UI(ID_ROI, OnUpdateRoi) ON_COMMAND(ID_ROI, OnRoi) //}}AFX_MSG_MAP END_MESSAGE_MAP() /* static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; */ static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_IMAGESIZE, ID_IMAGEBPP, ID_IMAGEMEM, ID_IMAGEDISK, }; static int parts[] = { 300, 320, 340, 360, -1, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { m_pBrowseDlg=NULL; m_bBrowse = FALSE; } CMainFrame::~CMainFrame() { if(m_pBrowseDlg) { m_pBrowseDlg->DestroyWindow(); delete m_pBrowseDlg; } } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC); 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 *(2/3)); m_wndStatusBar.GetPaneInfo(1, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(1, nID, nStyles, 75); m_wndStatusBar.GetPaneInfo(2, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(2, nID, nStyles, 35); m_wndStatusBar.GetPaneInfo(3, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(3, nID, nStyles, 90); m_wndStatusBar.GetPaneInfo(4, nID, nStyles, cxWidth); m_wndStatusBar.SetPaneInfo(4, nID, nStyles, 90); m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); return 0; } 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; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { // Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CMDIFrameWnd::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CMDIFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CMDIFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers void CMainFrame::OnFileBrowseforjpegjpeg2000() { GETDIRECTORYDLGPARAMS DlgParams; memset(&DlgParams, 0, sizeof(GETDIRECTORYDLGPARAMS)); DlgParams.uStructSize = sizeof(GETDIRECTORYDLGPARAMS); if(m_pBrowseDlg) { if(m_pBrowseDlg->m_hWnd && ::IsWindow(m_pBrowseDlg->m_hWnd)) m_pBrowseDlg->DestroyWindow(); } L_INT nRet; DlgParams.pszDirectory = theApp.m_szImageDir ; DlgParams.nBuffSize = _MAX_PATH; DlgParams.pszFilter = TEXT("JPEG,JPEG 2000,LEAD\0*.jpg;*.jpeg;*.jp2;*.j2k;*.cmp;*.cmw\0\0"); DlgParams.nFilterIndex = 1; DlgParams.pszTitle = TEXT("Select a Directory to Browse"); nRet = L_DlgGetDirectory(this->m_hWnd, &DlgParams); if(nRet!=SUCCESS_DLG_OK) return; if(!m_pBrowseDlg) m_pBrowseDlg = new CBrowseDlg(); if(!m_pBrowseDlg) MessageBox(TEXT("Out of memory!"), TEXT("Error"), MB_OK|MB_ICONERROR); //we want a modeless dialog. //m_pBrowseDlg->DoModal(); //we want a modeless dialog. if(m_pBrowseDlg->Create(IDD_DIALOG_BROWSE,this)) { m_pBrowseDlg->ShowWindow(SW_SHOW); m_bBrowse = TRUE; m_pBrowseDlg->m_szImageDir = theApp.m_szImageDir; m_pBrowseDlg->SendMessage(WM_BROWSE, 0, 0L); } } void CMainFrame::OnUpdateFileBrowseforjpegjpeg2000(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bBrowse?FALSE:TRUE); } 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() { L_DlgFree(); if(m_pBrowseDlg) { if(theApp.m_bInProcess) { theApp.m_bKillProgress =TRUE; return; } } CMDIFrameWnd::OnClose(); } void CMainFrame::OnPreferencesPaintscalingBicubic() { theApp.m_nPaintScaling = theApp.Paint_Bicubic; RedrawChildren(FALSE); } void CMainFrame::OnUpdatePreferencesPaintscalingBicubic(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_nPaintScaling == theApp.Paint_Bicubic); } void CMainFrame::OnPreferencesPaintscalingNormal() { theApp.m_nPaintScaling = theApp.Paint_Normal; RedrawChildren(FALSE); } void CMainFrame::OnUpdatePreferencesPaintscalingNormal(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_nPaintScaling == theApp.Paint_Normal); } void CMainFrame::OnPreferencesPaintscalingResample() { theApp.m_nPaintScaling = theApp.Paint_Resample; RedrawChildren(FALSE); } void CMainFrame::OnUpdatePreferencesPaintscalingResample(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_nPaintScaling == theApp.Paint_Resample); } BOOL CALLBACK RedrawChildrenCB(HWND hWnd, LPARAM lParam) { RedrawWindow(hWnd,0,0,RDW_INVALIDATE|RDW_ALLCHILDREN|(LOWORD(lParam) ? RDW_ERASE:0)); return(TRUE); } void CMainFrame::RedrawChildren(BOOL bErase) { EnumChildWindows(this->m_hWnd, (WNDENUMPROC)RedrawChildrenCB, bErase); return; } void CMainFrame::OnPreferencesProgressiveload() { theApp.m_bPaintWhileLoad = !theApp.m_bPaintWhileLoad; theApp.WriteProfileInt(TEXT("Settings"), TEXT("PaintWhileLoad"), theApp.m_bPaintWhileLoad); } void CMainFrame::OnUpdatePreferencesProgressiveload(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_bPaintWhileLoad); } void CMainFrame::OnUpdateRoi(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_bEnableROI); } void CMainFrame::OnRoi() { theApp.m_bEnableROI = !theApp.m_bEnableROI; if (theApp.m_bEnableROI == FALSE) RedrawChildren(FALSE); //theApp.WriteProfileInt("Settings", "RegionOfInterest", theApp.m_bEnableROI); }