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

📄 imagecamview.cpp

📁 《数字图象工程案例》原码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void CimageCAMView::OnPw4() 
{
	// TODO: Add your command handler code here
	SetPenWidth(4);
	ShowPenWidth();
}

void CimageCAMView::OnUpdatePw4(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetRadio(4== m_nPenWidth);
}

void CimageCAMView::OnPw5() 
{
	// TODO: Add your command handler code here
	SetPenWidth(5);
	ShowPenWidth();
}

void CimageCAMView::OnUpdatePw5(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetRadio(5== m_nPenWidth);
	
}

void CimageCAMView::OnPwOther() 
{
	// TODO: Add your command handler code here
	CPenWidth dlg(this);
	
	dlg.m_nPenWidth = m_nPenWidth;
	if (dlg.DoModal() == IDOK)
		SetPenWidth(dlg.m_nPenWidth);
}

void CimageCAMView::OnUpdatePwOther(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetRadio(5< m_nPenWidth);
}

void CimageCAMView::OnFont() 
{
	// TODO: Add your command handler code here
	LOGFONT lf;
	m_pFont->GetLogFont(&lf);
	CFontDialog dlg(&lf, CF_SCREENFONTS);
	if (dlg.DoModal() == IDOK)
	{
		dlg.GetCurrentFont(&lf);
		m_pFont->DeleteObject();
		m_pFont->CreateFontIndirect(&lf);
		
		if (::IsWindow(m_EditText.m_hWnd))
		{
			CString s;
			m_EditText.GetWindowText(s);
			
			CClientDC dc(this);
			CFont *pOldFont = dc.SelectObject(m_pFont);
			// needed rectangle
			CRect rect(0,0,1,1);
			dc.DrawText(s, &rect, DT_CALCRECT);
			dc.SelectObject(pOldFont);
			
			CRect rc;
			m_EditText.GetWindowRect(&rc);
			ScreenToClient(&rc);
			if (rc.Height() < rect.Height())
				rc.bottom = rc.top + rect.Height();
			if (rc.Width() < rect.Width())
				rc.right = rc.left + rect.Width();
			ClientToDib(rc);
			if (rc.bottom > m_pDib->GetHeight())
				rc.bottom = m_pDib->GetHeight();
			if (rc.right > m_pDib->GetWidth())
				rc.right = m_pDib->GetWidth();
			DibToClient(rc);
			
			// new edit
			m_EditText.SetWindowPos(NULL,0,0,rc.Width(),rc.Height(),SWP_NOMOVE|SWP_NOZORDER);
			m_EditText.SetFont(m_pFont);
			m_EditText.Invalidate();
			
			// new frame
			m_EditText.GetWindowRect(&rc);
			ScreenToClient(&rc);
			rc.InflateRect(3,3);
			InvalidateRect(&rc);
		}
	}
}


void CimageCAMView::OnLeft() 
{
	// TODO: Add your command handler code here
	m_nTextAlign = DT_LEFT;
	if (::IsWindow(m_EditText.m_hWnd))
	{
		CRect rc;
		m_EditText.GetWindowRect(&rc);
		ScreenToClient(&rc);
		CString s;
		m_EditText.GetWindowText(s);
		
		m_EditText.DestroyWindow();
		m_EditText.Create(WS_VISIBLE|WS_CHILD|ES_LEFT|ES_MULTILINE, 
			rc, 
			this, 
			IDC_EDIT);
		
		m_EditText.SetWindowText(s);
	}
}

void CimageCAMView::OnUpdateLeft(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetRadio(DT_LEFT == m_nTextAlign);
}

void CimageCAMView::OnCenter() 
{
	// TODO: Add your command handler code here
	m_nTextAlign = DT_CENTER;
	if (::IsWindow(m_EditText.m_hWnd))
	{
		CRect rc;
		m_EditText.GetWindowRect(&rc);
		ScreenToClient(&rc);
		CString s;
		m_EditText.GetWindowText(s);
		
		m_EditText.DestroyWindow();
		m_EditText.Create(WS_VISIBLE|WS_CHILD|ES_CENTER|ES_MULTILINE, 
			rc, 
			this, 
			IDC_EDIT);
		
		m_EditText.SetWindowText(s);
	}
}

void CimageCAMView::OnUpdateCenter(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetRadio(DT_CENTER == m_nTextAlign);
}

void CimageCAMView::OnRight() 
{
	// TODO: Add your command handler code here
	m_nTextAlign = DT_RIGHT;
	if (::IsWindow(m_EditText.m_hWnd))
	{
		CRect rc;
		m_EditText.GetWindowRect(&rc);
		ScreenToClient(&rc);
		CString s;
		m_EditText.GetWindowText(s);
		
		m_EditText.DestroyWindow();
		m_EditText.Create(WS_VISIBLE|WS_CHILD|ES_RIGHT|ES_MULTILINE, 
			rc, 
			this, 
			IDC_EDIT);
		
		m_EditText.SetWindowText(s);
	}
}

void CimageCAMView::OnUpdateRight(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetRadio(DT_RIGHT == m_nTextAlign);
	
}


void CimageCAMView::OnEditSelectAll() 
{
	// TODO: Add your command handler code here
	m_rcClip = CRect(0, 0, m_pDib->GetWidth(), m_pDib->GetHeight());
	
	// create float DIB
	HDIB hDib = m_pDib->CopyRect(m_rcClip);
	
	// create new float DIB window
	CreateFloatWnd(hDib, m_rcClip.TopLeft());
}

void CimageCAMView::OnUpdateEditSelectAll(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}



void CimageCAMView::OnEditPaste() 
{
	// TODO: Add your command handler code here
	Paste();
}

void CimageCAMView::OnEditCut() 
{
	// TODO: Add your command handler code here
	Cut();
}

void CimageCAMView::OnUpdateEditCut(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnEditCopy() 
{
	// TODO: Add your command handler code here
	CopyToClipboard();
}

void CimageCAMView::OnUpdateEditCopy(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnEditClear() 
{
	// TODO: Add your command handler code here
	Delete();
}

void CimageCAMView::OnUpdateEditClear(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnCopyto() 
{
	// TODO: Add your command handler code here
	HDIB hDib;
	// if there is float dib, copy it
	if (m_pFloatWnd)
		hDib = CopyHandle(m_pFloatWnd->m_hDibFloat);
	else	// otherwise, copy the entire DIB
		hDib = CopyHandle(m_pDib->m_hDib);
	
	CDib dib;
	if (! dib.Attach(hDib))
		return;
	
	CFileDialog FileDlg(FALSE, "*.bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szSaveFilter);
	
	switch (dib.GetBitCount())
	{
	case 1:
		FileDlg.m_ofn.nFilterIndex = 1;
		break;
	case 4:
		FileDlg.m_ofn.nFilterIndex = 2;
		break;
	case 8:
		FileDlg.m_ofn.nFilterIndex = 3;
		break;
	case 24:
	default:
		FileDlg.m_ofn.nFilterIndex = 4;
		break;
	}
	
	if (FileDlg.DoModal() == IDOK)
	{
		switch (FileDlg.m_ofn.nFilterIndex)
		{
		case 1:
			dib.ConvertFormat(1);
			break;
		case 2:
			dib.ConvertFormat(4);
			break;
		case 3:
			dib.ConvertFormat(8);
			break;
		case 4:
		default:
			dib.ConvertFormat(24);
			break;
		}
		dib.Save(FileDlg.m_ofn.lpstrFile);
	}
}

void CimageCAMView::OnUpdateCopyto(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnPastefrom() 
{
	// TODO: Add your command handler code here
	
	CFileDialog FileDlg(TRUE, "*.bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szOpenFilter);
	
	if (FileDlg.DoModal() == IDOK)
	{
		CDib dib;
		if (dib.Load(FileDlg.m_ofn.lpstrFile))
		{
			// adjust position with scroll position
			CRect rc(0, 0, dib.GetWidth(), dib.GetHeight());
			
			// create float DIB
			HDIB hDib = CopyHandle(dib.GetHandle());
			
			if (AdjustSize(hDib))
				// create new float DIB window
				CreateFloatWnd(hDib, rc.TopLeft());
		}
	}
}

void CimageCAMView::OnUpdatePastefrom(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
	
}
void CimageCAMView::Paste()
{
	if (! PasteDibFromClipboard())
		if (! PasteBitmapFromClipboard())
			PastePalFromClipboard();
}


void CimageCAMView::OnNorthwest() 
{
	// TODO: Add your command handler code here
	EdgeEnhance(NORTHWEST);
}

void CimageCAMView::OnUpdateNorthwest(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnNortheast() 
{
	// TODO: Add your command handler code here
	EdgeEnhance(NORTHEAST);
}

void CimageCAMView::OnUpdateNortheast(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnNorth() 
{
	// TODO: Add your command handler code here
	EdgeEnhance(NORTH);
}

void CimageCAMView::OnUpdateNorth(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnMm() 
{
	// TODO: Add your command handler code here
	SetLengthUnit(MM_HIMETRIC);
}

void CimageCAMView::OnUpdateMm(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

void CimageCAMView::OnLf3() 
{
	// TODO: Add your command handler code here
	CConvoluteDlg FD(1,10,3,this);
	if (FD.DoModal() == IDOK)
	{
		CimageCAMDoc* pDoc = GetDocument();
		MergeFloatDib();
		pDoc->WriteTmpFile();
		m_pDib->LowPass(FD.m_nStreng, FILTER3);
		pDoc->SetModifiedFlag(TRUE);
		OnRealizePal((WPARAM)m_hWnd,0);  // realize the new palette
		pDoc->UpdateAllViews(NULL);
	}
}

void CimageCAMView::OnUpdateLf3(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnLf2() 
{
	// TODO: Add your command handler code here
	
	CConvoluteDlg FD(1,10,3,this);
	if (FD.DoModal() == IDOK)
	{
		CimageCAMDoc* pDoc = GetDocument();
		MergeFloatDib();
		pDoc->WriteTmpFile();
		m_pDib->LowPass(FD.m_nStreng, FILTER2);
		pDoc->SetModifiedFlag(TRUE);
		OnRealizePal((WPARAM)m_hWnd,0);  // realize the new palette
		pDoc->UpdateAllViews(NULL);
	}
}

void CimageCAMView::OnUpdateLf2(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnLf1() 
{
	// TODO: Add your command handler code here
	
	CConvoluteDlg FD(1,10,3,this);
	if (FD.DoModal() == IDOK)
	{
        
		CimageCAMDoc* pDoc = GetDocument();
		MergeFloatDib();
		pDoc->WriteTmpFile();
		m_pDib->LowPass(FD.m_nStreng, FILTER1);
		pDoc->SetModifiedFlag(TRUE);
		OnRealizePal((WPARAM)m_hWnd,0);  // realize the new palette
		pDoc->UpdateAllViews(NULL);
	}
}

void CimageCAMView::OnInch() 
{
	// TODO: Add your command handler code here
	SetLengthUnit(MM_HIENGLISH);
}

void CimageCAMView::OnUpdateInch(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

void CimageCAMView::OnHough() 
{
	// TODO: Add your command handler code here
	EdgeEnhance(HOUGH);
}

void CimageCAMView::OnUpdateHough(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnHorz() 
{
	// TODO: Add your command handler code here
	EdgeEnhance(HORZ);
}

void CimageCAMView::OnUpdateHorz(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnHmirror() 
{
	// TODO: Add your command handler code here
	CimageCAMDoc* pDoc = GetDocument();
	MergeFloatDib();
    pDoc->WriteTmpFile();
	Flip(MD_HORZ);
	
	
	CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
	SetScrollSizes(MM_TEXT, sizeTotal);
	pDoc->SetModifiedFlag(TRUE);
	pDoc->UpdateAllViews(NULL);
}

void CimageCAMView::OnUpdateHmirror(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(! m_pDib->IsEmpty());
}

void CimageCAMView::OnHf3() 
{
	// TODO: Add your command handler code here
	CConvoluteDlg FD(1,10,3,this);
	if (FD.DoModal() == IDOK)
	{

⌨️ 快捷键说明

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