⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dibview.cpp

📁 这是一款蛮COOL的图像处理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
	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);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -