DIBView.cpp
上传用户:gzboli
上传日期:2013-04-10
资源大小:471k
文件大小:20k
- // DIBView.cpp : implementation of the CDIBView class
- //
- #include "stdafx.h"
- #include "QuickImage.h"
- #include "DIBDoc.h"
- #include "DIBView.h"
- #include "Piccontrol.h"
- //#include "MathEx.h"
- #include <math.h>
- #include "resource.h"
- #include "MainFrm.h"
- #include "Global.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDIBView
- extern CString g_strCurrentDir;
- extern bool g_bShowHide;
- extern CList<CString,CString&> g_strImgFileNames;
- IMPLEMENT_DYNCREATE(CDIBView, CView)
- BEGIN_MESSAGE_MAP(CDIBView, CView)
- ON_WM_CONTEXTMENU()
- //{{AFX_MSG_MAP(CDIBView)
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_WM_KEYDOWN()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- ON_COMMAND_RANGE(ID_MAP_PAN, ID_MAP_SCISSOR, OnMapButton)
- ON_UPDATE_COMMAND_UI_RANGE(ID_MAP_PAN, ID_MAP_SCISSOR, OnUpdateMapButtonState)
- ON_COMMAND_RANGE(ID_DIR_HOME, ID_DIR_END, OnDirButtons)
- ON_UPDATE_COMMAND_UI_RANGE(ID_DIR_HOME, ID_DIR_END, OnUpdateDirButtons)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDIBView construction/destruction
- CDIBView::CDIBView()
- {
- m_uIDMapButton = UINT_MAX;
- m_ptMouseDown.x=m_ptMouseDown.y=-1;
- m_ptTracing.x = m_ptTracing.y = 0;
- m_ptFirst.x = m_ptFirst.y = -1;
- m_iBacks = 0;
- m_iMaxBacks = 10;
- m_dMeasure = 0.0;
- }
- CDIBView::~CDIBView()
- {
- }
- BOOL CDIBView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- // cs.lpszClass = AfxRegisterWndClass(NULL,AfxGetApp()->LoadCursor(IDC_AIM),
- // 0,0);
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDIBView drawing
- void CDIBView::OnDraw(CDC* pDC)
- {
- CDIBDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- HDIB hDIB = pDoc->GetHDIB();
- if (hDIB != NULL)
- {
- CRect rcDest , rcDIB;
- if (pDC->IsPrinting()) // printer DC
- {
- LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
- int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x
- int cyDIB = (int) abs(::DIBHeight(lpDIB)); // Size of DIB - y
- ::GlobalUnlock((HGLOBAL) hDIB);
- rcDIB.top = rcDIB.left = 0;
- rcDIB.right = cxDIB;
- rcDIB.bottom = cyDIB;
- // get size of printer page (in pixels)
- int cxPage = pDC->GetDeviceCaps(HORZRES);
- int cyPage = pDC->GetDeviceCaps(VERTRES);
- // get printer pixels per inch
- int cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
- int cyInch = pDC->GetDeviceCaps(LOGPIXELSY);
- //
- // Best Fit case -- create a rectangle which preserves
- // the DIB's aspect ratio, and fills the page horizontally.
- //
- // The formula in the "->bottom" field below calculates the Y
- // position of the printed bitmap, based on the size of the
- // bitmap, the width of the page, and the relative size of
- // a printed pixel (cyInch / cxInch).
- //
- rcDest.top = rcDest.left = 0;
- rcDest.bottom = (int)(((double)cyDIB * cxPage * cyInch)
- / ((double)cxDIB * cxInch));
- rcDest.right = cxPage;
- }
- else // not printer DC
- {
- GetClientRect(&rcDest);
- CPicControl::CalcuRect(rcDest, rcDIB, m_ptDIBCenter, hDIB, m_dZoom);
- }
- ::PaintDIB(pDC->m_hDC, &rcDest, pDoc->GetHDIB(),
- &rcDIB, pDoc->GetDocPalette());
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDIBView printing
- BOOL CDIBView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CDIBView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CDIBView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDIBView diagnostics
- #ifdef _DEBUG
- void CDIBView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CDIBView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CDIBDoc* CDIBView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDIBDoc)));
- return (CDIBDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CDIBView message handlers
- void CDIBView::OnInitialUpdate()
- {
- CView::OnInitialUpdate();
-
- HDIB hDIB = GetDocument()->GetHDIB();
- int cxDIB,cyDIB;
- if (hDIB != NULL)
- {
- LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
- cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x
- cyDIB = (int) abs(::DIBHeight(lpDIB)); // Size of DIB - y
- ::GlobalUnlock((HGLOBAL) hDIB);
-
- m_ptDIBCenter.x = cxDIB/2;
- m_ptDIBCenter.y = cyDIB/2;
-
- CRect rcDC;
- GetClientRect(&rcDC);
-
- if(cxDIB > rcDC.Width() || cyDIB > rcDC.Height())
- {
- m_dZoom = CPicControl::ViewFit(m_ptDIBCenter, rcDC, hDIB);
- }
- else
- {
- m_dZoom = CPicControl::ViewActual(m_ptDIBCenter, rcDC, hDIB);
- }
-
- CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
- ASSERT(NULL != pMainWnd);
- CString strText;
- strText.Format("Image Size: %d,%d", cxDIB, cyDIB);
- pMainWnd->SetStatusText(1, (LPCTSTR)strText);
-
- strText.Format("Zoom: %d%%",
- int(100.0 / m_dZoom));
- pMainWnd->SetStatusText(2, (LPCTSTR)strText);
- }
- }
- void CDIBView::OnMapButton(UINT uID)
- {
- CRect rcView;
- GetClientRect(&rcView);
- switch(uID)
- {
- case ID_MAP_ACTUAL:
- Push();
- m_dZoom = CPicControl::ViewActual(m_ptDIBCenter, rcView, GetDocument()->GetHDIB());
- m_uIDMapButton = UINT_MAX;
- Invalidate();
- SetStatusText();
- break;
- case ID_MAP_FIT:
- Push();
- m_dZoom = CPicControl::ViewFit(m_ptDIBCenter, rcView, GetDocument()->GetHDIB());
- m_uIDMapButton = UINT_MAX;
- Invalidate();
- SetStatusText();
- break;
- case ID_MAP_VIEWPREVIOUS:
- if(m_iBacks > 0)
- {
- PICCONTROL a = Pop();
- m_ptDIBCenter.x = a.x;
- m_ptDIBCenter.y = a.y;
- m_dZoom = a.zoom;
- Invalidate();
- SetStatusText();
- }
- m_uIDMapButton = UINT_MAX;
- break;
- case ID_MAP_ZOOMOUT:
- BeginWaitCursor();
- Push();
- m_dZoom = CPicControl::ZoomOut(m_dZoom);
- Invalidate();
- EndWaitCursor();
- m_uIDMapButton = UINT_MAX;
- SetStatusText();
- break;
- case ID_MAP_ZOOMIN:
- BeginWaitCursor();
- Push();
- m_dZoom = CPicControl::ZoomIn(m_dZoom);
- Invalidate();
- EndWaitCursor();
- m_uIDMapButton = UINT_MAX;
- SetStatusText();
- break;
- default:
- m_uIDMapButton = (m_uIDMapButton == uID) ? UINT_MAX : uID;
- break;
- }
- }
- void CDIBView::OnUpdateMapButtonState(CCmdUI* pCmdUI)
- {
- if(ID_MAP_VIEWPREVIOUS == pCmdUI->m_nID)
- // && ID_MAP_VIEWPREVIOUS == m_uIDMapButton)
- {
- pCmdUI->SetCheck(FALSE);
- pCmdUI->Enable(m_iBacks > 0);
- }
- else
- {
- pCmdUI->SetCheck(pCmdUI->m_nID == m_uIDMapButton);
- }
- }
- void CDIBView::OnMouseMove(UINT nFlags, CPoint point)
- {
- CDC *pDC=GetDC();
- ASSERT_VALID(pDC);
- int iOldROP;
- CBrush* pOldBrush;
- CPen* pOldPen;
- CPen pen;
- CRect rcTracing(m_ptMouseDown,m_ptTracing);
-
- switch(m_uIDMapButton)
- {
- case ID_MAP_PAN://pan
- if(nFlags & MK_LBUTTON)
- {
- SetCursor(AfxGetApp()->LoadCursor(IDC_HANDD));
- // ::ZoomPan(m_ptDIBCenter, m_ptMouseDown, point, m_dZoom);
- m_ptDIBCenter.x -= int((point.x-m_ptMouseDown.x)*m_dZoom);
- m_ptDIBCenter.y -= int((point.y-m_ptMouseDown.y)*m_dZoom);
- m_ptMouseDown=point;
- Invalidate();
- }
- else
- {
- SetCursor(AfxGetApp()->LoadCursor(IDC_HANDU));
- }
- break;
- case ID_MAP_ZOOMOUT://Zoom +
- // SetCursor(AfxGetApp()->LoadCursor(IDC_ZOOMOUT));
- break;
- case ID_MAP_ZOOMIN://Zoom -
- // SetCursor(AfxGetApp()->LoadCursor(IDC_ZOOMIN));
- break;
- case ID_MAP_ZOOMWINDOW://zoom window
- if(nFlags & MK_LBUTTON)
- {
- SetCursor(AfxGetApp()->LoadCursor(IDC_ZOOMWINDOW));
- iOldROP = pDC->SetROP2(R2_XORPEN);
- pen.CreatePen(PS_DOT,1,RGB(0,0,255));
- pOldBrush=(CBrush*)pDC->SelectStockObject(NULL_BRUSH);
- pOldPen=pDC->SelectObject(&pen);
-
- rcTracing.NormalizeRect();
- pDC->Rectangle(&rcTracing);
- m_ptTracing = point;
- rcTracing.TopLeft() = m_ptMouseDown;
- rcTracing.BottomRight() = m_ptTracing;
- rcTracing.NormalizeRect();
- pDC->Rectangle(&rcTracing);
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- pDC->SetROP2(iOldROP);
- }
- break;
- case ID_MAP_ACTUAL://view actual size
- break;
- case ID_MAP_FIT://view fit in
- break;
- case ID_MAP_SCISSOR://Scissor
- /*
- // if(nFlags & MK_LBUTTON)//if(m_ptTracing.x != 0 || m_ptTracing.y != 0)
- {
- iOldROP = pDC->SetROP2(R2_NOT);
- pDC->MoveTo(0, m_ptTracing.y);
- pDC->LineTo(1024, m_ptTracing.y);
- pDC->MoveTo(m_ptTracing.x, 0);
- pDC->LineTo(m_ptTracing.x, 768);
- // TRACE("nO:%dt%d",m_ptTracing.x,m_ptTracing.y);
- m_ptTracing = point;
- // TRACE("nN:%dt%d",m_ptTracing.x,m_ptTracing.y);
- pDC->MoveTo(0, m_ptTracing.y);
- pDC->LineTo(1024, m_ptTracing.y);
- pDC->MoveTo(m_ptTracing.x, 0);
- pDC->LineTo(m_ptTracing.x, 768);
- pDC->SetROP2(iOldROP);
- }*/
- SetCursor(AfxGetApp()->LoadCursor(IDC_SCISSOR));
- if(nFlags & MK_LBUTTON)
- {
- iOldROP = pDC->SetROP2(R2_XORPEN);
- pen.CreatePen(PS_DOT,1,RGB(0,0,255));
- pOldBrush=(CBrush*)pDC->SelectStockObject(NULL_BRUSH);
- pOldPen=pDC->SelectObject(&pen);
-
- rcTracing.NormalizeRect();
- pDC->Rectangle(&rcTracing);
- m_ptTracing = point;
- rcTracing.TopLeft() = m_ptMouseDown;
- rcTracing.BottomRight() = m_ptTracing;
- rcTracing.NormalizeRect();
- pDC->Rectangle(&rcTracing);
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- pDC->SetROP2(iOldROP);
- }
- break;
- default:
- // ASSERT(FALSE);
- break;
- }
- CView::OnMouseMove(nFlags, point);
- }
- void CDIBView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- CPen pen, *pOldPen = NULL;
- CDC *pDC = GetDC();
- ASSERT(NULL != pDC);
- switch(m_uIDMapButton)
- {
- case ID_MAP_PAN://pan
- SetCursor(AfxGetApp()->LoadCursor(IDC_HANDD));
- break;
- case ID_MAP_ZOOMOUT://zoom +
- break;
- case ID_MAP_ZOOMIN://zoom -
- break;
- case ID_MAP_ZOOMWINDOW://zoom window
- SetCursor(AfxGetApp()->LoadCursor(IDC_ZOOMWINDOW));
- break;
- case ID_MAP_ACTUAL://view actual size
- break;
- case ID_MAP_FIT://view fit in
- break;
- case ID_MAP_SCISSOR://Scissor
- break;
- default:
- // ASSERT(FALSE);
- break;
- }
- m_ptTracing = m_ptMouseDown = point;
-
- CView::OnLButtonDown(nFlags, point);
- }
- void CDIBView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- CDC *pDC=GetDC();
- ASSERT_VALID(pDC);
- int iOldROP;
- CBrush* pOldBrush;
- CPen* pOldPen;
- CRect rcTracing(m_ptMouseDown,m_ptTracing);
- CPen pen;
- switch(m_uIDMapButton)
- {
- case ID_MAP_PAN://pan
- SetCursor(AfxGetApp()->LoadCursor(IDC_HANDU));
- Push();
- break;
- case ID_MAP_ZOOMOUT://zoom +
- break;
- case ID_MAP_ZOOMIN://zoom -
- break;
- case ID_MAP_ZOOMWINDOW://zoom window
- iOldROP = pDC->SetROP2(R2_XORPEN);
- pen.CreatePen(PS_DOT,1,RGB(0,0,255));
- pOldBrush=(CBrush*)pDC->SelectStockObject(NULL_BRUSH);
- pOldPen=pDC->SelectObject(&pen);
-
- rcTracing.NormalizeRect();
- pDC->Rectangle(&rcTracing);
-
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- pDC->SetROP2(iOldROP);
-
- rcTracing.TopLeft() = m_ptMouseDown;
- rcTracing.BottomRight() = point;
- rcTracing.NormalizeRect();
- if(rcTracing.Width() > 5 && rcTracing.Height() > 5)
- {
- CRect rcView;
- GetClientRect(&rcView);
- Push();
- m_dZoom = CPicControl::ZoomWindow(m_ptDIBCenter, rcView, rcTracing, m_dZoom);
- Invalidate();
- SetStatusText();
- }
- break;
- case ID_MAP_ACTUAL://view actual size
- break;
- case ID_MAP_FIT://view fit in
- break;
- case ID_MAP_SCISSOR://Scissor
- iOldROP = pDC->SetROP2(R2_XORPEN);
- pen.CreatePen(PS_DOT,1,RGB(0,0,255));
- pOldBrush=(CBrush*)pDC->SelectStockObject(NULL_BRUSH);
- pOldPen=pDC->SelectObject(&pen);
-
- rcTracing.NormalizeRect();
- pDC->Rectangle(&rcTracing);
-
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldBrush);
- pDC->SetROP2(iOldROP);
- rcTracing.TopLeft() = m_ptMouseDown;
- rcTracing.BottomRight() = point;
- rcTracing.NormalizeRect();
- break;
- default:
- // ASSERT(FALSE);
- break;
- }
- CView::OnLButtonUp(nFlags, point);
- }
- void CDIBView::Push()
- {
- if(m_iBacks < m_iMaxBacks)
- {
- m_Pipe[m_iBacks].x = m_ptDIBCenter.x;
- m_Pipe[m_iBacks].y = m_ptDIBCenter.y;
- m_Pipe[m_iBacks].zoom = m_dZoom;
- m_iBacks ++;
- }
- else
- {
- for(int i =0; i < m_iBacks -1; i++)
- {
- m_Pipe[i] = m_Pipe[i + 1];
- }
- m_Pipe[m_iBacks -1].x = m_ptDIBCenter.x;
- m_Pipe[m_iBacks -1].y = m_ptDIBCenter.y;
- m_Pipe[m_iBacks -1].zoom = m_dZoom;
- }
- }
- PICCONTROL CDIBView::Pop()
- {
- ASSERT(m_iBacks > 0);
- m_iBacks --;
- return m_Pipe[m_iBacks];
- }
- void CDIBView::OnContextMenu(CWnd*, CPoint point)
- {
- // CG: This block was added by the Pop-up Menu component
- {
- if (point.x == -1 && point.y == -1){
- //keystroke invocation
- CRect rect;
- GetClientRect(rect);
- ClientToScreen(rect);
- point = rect.TopLeft();
- point.Offset(5, 5);
- }
- CMenu menu;
- VERIFY(menu.LoadMenu(CG_IDR_POPUP_DIBVIEW));
- CMenu* pPopup = menu.GetSubMenu(0);
- ASSERT(pPopup != NULL);
- CWnd* pWndPopupOwner = this;
- while (pWndPopupOwner->GetStyle() & WS_CHILD)
- pWndPopupOwner = pWndPopupOwner->GetParent();
- pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
- pWndPopupOwner);
- }
- }
- void CDIBView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
- if((nChar == 107) || (nChar == 187))//+ =
- {
- // CPicControl::ZoomIn(m_dZoom);
- m_dZoom /= 2.0;
- Invalidate();
- SetStatusText();
- }
- else if((nChar == 109) || (nChar == 189))//- _
- {
- // CPicControl::ZoomOut(m_dZoom);
- m_dZoom *= 2.0;
- Invalidate();
- SetStatusText();
- }
- else if(nChar == 38)//UpArrow
- {
- CRect rcDC;
- GetClientRect(&rcDC);
- m_ptDIBCenter.y += int((double)rcDC.Height() / 6.0 * m_dZoom);
- Invalidate();
- }
- else if(nChar == 40)//Down arrow
- {
- CRect rcDC;
- GetClientRect(&rcDC);
- m_ptDIBCenter.y -= int((double)rcDC.Height() / 6.0 * m_dZoom);
- Invalidate();
- }
- else if(nChar == 37)//Left arrow
- {
- CRect rcDC;
- GetClientRect(&rcDC);
- m_ptDIBCenter.x += int((double)rcDC.Width() / 6.0 * m_dZoom);
- Invalidate();
- }
- else if(nChar == 39)//right arrow
- {
- CRect rcDC;
- GetClientRect(&rcDC);
- m_ptDIBCenter.x -= int((double)rcDC.Width() / 6.0 * m_dZoom);
- Invalidate();
- }
- else if(nChar == 34)//Page Down
- {
- if(!g_strImgFileNames.IsEmpty())
- {
- const char *pTitle = strrchr(GetDocument()->GetPathName(), '\');
- CString strOldFileName = ++pTitle;
- POSITION pos = g_strImgFileNames.Find(strOldFileName);
- if(NULL != pos)
- {
- g_strImgFileNames.GetNext(pos);
- if(NULL != pos)
- {
- strOldFileName = g_strImgFileNames.GetAt(pos);
- GetDocument()->EnumFile(g_strCurrentDir + g_strImgFileNames.GetAt(pos));
- CPicControl::ViewIdeal(m_ptDIBCenter, m_dZoom, this, GetDocument()->GetHDIB());
- Invalidate();
- SetStatusText();
- }
- }
- }
- }
- else if(nChar == 33)//Page Up
- {
- if(!g_strImgFileNames.IsEmpty())
- {
- const char *pTitle = strrchr(GetDocument()->GetPathName(), '\');
- CString strOldFileName = ++pTitle;
- POSITION pos = g_strImgFileNames.Find(strOldFileName);
- if(NULL != pos)
- {
- g_strImgFileNames.GetPrev(pos);
- if(NULL != pos)
- {
- GetDocument()->EnumFile(g_strCurrentDir + g_strImgFileNames.GetAt(pos));
- CPicControl::ViewIdeal(m_ptDIBCenter, m_dZoom, this, GetDocument()->GetHDIB());
- Invalidate();
- SetStatusText();
- }
- }
- }
- }
- else if(nChar == 36)//Home
- {
- if(!g_strImgFileNames.IsEmpty())
- {
- POSITION pos = g_strImgFileNames.GetHeadPosition();
- if(NULL != pos)
- {
- GetDocument()->EnumFile(g_strCurrentDir + g_strImgFileNames.GetAt(pos));
- CPicControl::ViewIdeal(m_ptDIBCenter, m_dZoom, this, GetDocument()->GetHDIB());
- Invalidate();
- SetStatusText();
- }
- }
- }
- else if(nChar == 35)//End
- {
- if(!g_strImgFileNames.IsEmpty())
- {
- POSITION pos = g_strImgFileNames.GetTailPosition();
- if(NULL != pos)
- {
- GetDocument()->EnumFile(g_strCurrentDir + g_strImgFileNames.GetAt(pos));
- CPicControl::ViewIdeal(m_ptDIBCenter, m_dZoom, this, GetDocument()->GetHDIB());
- Invalidate();
- SetStatusText();
- }
- }
- }
- else if(nChar == 46)//Delete
- {
- if(!g_strImgFileNames.IsEmpty())
- {
- CString strOldFileName = GetDocument()->GetTitle();
- POSITION posThis = g_strImgFileNames.Find(strOldFileName);
- if(NULL != posThis)
- {
- POSITION pos = posThis;
- g_strImgFileNames.GetNext(pos);
- if(NULL != pos)
- {
- GetDocument()->EnumFile(g_strCurrentDir + g_strImgFileNames.GetAt(pos));
- CPicControl::ViewIdeal(m_ptDIBCenter, m_dZoom, this, GetDocument()->GetHDIB());
- Invalidate();
- SetStatusText();
- }
- }
- g_strImgFileNames.RemoveAt(posThis);
- }
- DeleteFile(GetDocument()->GetPathName());
- }
- else
- {
- }
- }
- void CDIBView::SetStatusText()
- {
- HDIB hDIB = GetDocument()->GetHDIB();
- if(NULL != hDIB)
- {
- LPSTR lpDIB = (LPSTR)::GlobalLock(hDIB);
- int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x
- int cyDIB = (int) abs(::DIBHeight(lpDIB)); // Size of DIB - y
- ::GlobalUnlock((HGLOBAL) hDIB);
-
- CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
- ASSERT(NULL != pMainWnd);
- CString strText;
- strText.Format("Image Size: %d,%d", cxDIB, cyDIB);
- pMainWnd->SetStatusText(1, (LPCTSTR)strText);
-
- strText.Format("Zoom: %d%%",
- int(100.0 / m_dZoom));
- pMainWnd->SetStatusText(2, (LPCTSTR)strText);
- }
- }
- void CDIBView::OnDirButtons(UINT nID)
- {
- switch(nID)
- {
- case ID_DIR_HOME:
- if(!g_strImgFileNames.IsEmpty())
- {
- POSITION pos = g_strImgFileNames.GetHeadPosition();
- if(NULL != pos)
- {
- GetDocument()->EnumFile(g_strCurrentDir + g_strImgFileNames.GetAt(pos));
- CPicControl::ViewIdeal(m_ptDIBCenter, m_dZoom, this, GetDocument()->GetHDIB());
- Invalidate();
- SetStatusText();
- }
- }
- break;
- case ID_DIR_PREV:
- if(!g_strImgFileNames.IsEmpty())
- {
- CString strOldFileName = GetDocument()->GetTitle();
- POSITION pos = g_strImgFileNames.Find(strOldFileName);
- if(NULL != pos)
- {
- g_strImgFileNames.GetPrev(pos);
- if(NULL != pos)
- {
- GetDocument()->EnumFile(g_strCurrentDir + g_strImgFileNames.GetAt(pos));
- CPicControl::ViewIdeal(m_ptDIBCenter, m_dZoom, this, GetDocument()->GetHDIB());
- Invalidate();
- SetStatusText();
- }
- }
- }
- break;
- case ID_DIR_NEXT:
- if(!g_strImgFileNames.IsEmpty())
- {
- CString strOldFileName = GetDocument()->GetTitle();
- POSITION pos = g_strImgFileNames.Find(strOldFileName);
- if(NULL != pos)
- {
- g_strImgFileNames.GetNext(pos);
- if(NULL != pos)
- {
- GetDocument()->EnumFile(g_strCurrentDir + g_strImgFileNames.GetAt(pos));
- CPicControl::ViewIdeal(m_ptDIBCenter, m_dZoom, this, GetDocument()->GetHDIB());
- Invalidate();
- SetStatusText();
- }
- }
- }
- break;
- case ID_DIR_END:
- if(!g_strImgFileNames.IsEmpty())
- {
- POSITION pos = g_strImgFileNames.GetTailPosition();
- if(NULL != pos)
- {
- GetDocument()->EnumFile(g_strCurrentDir + g_strImgFileNames.GetAt(pos));
- CPicControl::ViewIdeal(m_ptDIBCenter, m_dZoom, this, GetDocument()->GetHDIB());
- Invalidate();
- SetStatusText();
- }
- }
- break;
- default:
- break;
- }
- }
- void CDIBView::OnUpdateDirButtons(CCmdUI *pCmdUI)
- {
- pCmdUI->Enable(TRUE);
- }