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

📄 picedit.cpp

📁 无线图象监控系统(用VC++编程)用数据库ACCESS存储图象
💻 CPP
字号:
// PicEdit.cpp : implementation file
//

#include "stdafx.h"
#include "MoinorCentre.h"
#include "DectectSet.h"
#include "MoinorCentreDlg.h"
#include "PicEdit.h"
#include"PictureList.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPicEdit dialog


CPicEdit::CPicEdit(CWnd* pParent /*=NULL*/)
	: CDialog(CPicEdit::IDD, pParent)
{srcselect=FALSE;
 drawtype=0;
rectopsel=FALSE;
	//{{AFX_DATA_INIT(CPicEdit)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CPicEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPicEdit)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPicEdit, CDialog)
	//{{AFX_MSG_MAP(CPicEdit)
	ON_WM_PAINT()
	ON_WM_CLOSE()
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_TUZHANG, OnTuzhang)
	ON_WM_SETCURSOR()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_RECTANGE, OnRectange)
	ON_BN_CLICKED(IDC_PEN, OnPen)
	ON_WM_LBUTTONUP()
	ON_BN_CLICKED(IDC_OK, OnOk)
	ON_BN_CLICKED(IDC_FINISH, OnFinish)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPicEdit message handlers

void CPicEdit::OnPaint() 
{ 
	CPaintDC dc(this); // device context for painting
	CRect rec;
	//CDC* cdc=GetDlgItem(IDC_PICTURE)->GetDC();
CDC* pdc=GetDC();

GetDlgItem(IDC_PICTURE)->GetWindowRect(rec);
       ScreenToClient(&rec);
//((CPictureList*)GetParent())->dibview.Display(cdc,0,0);
	// TODO: Add your message handler code here
//GetDlgItem(IDC_PICTURE)->ReleaseDC(cdc);	
((CPictureList*)GetParent())->dibview.Display(pdc,rec.TopLeft().x,rec.TopLeft().y);

ReleaseDC(pdc);
	// Do not call CDialog::OnPaint() for painting messages
}

void CPicEdit::OnClose() 
{m_brush.DeleteObject();
	// TODO: Add your message handler code here and/or call default
	GetParent()->KillTimer(1);
	DestroyWindow();

}

void CPicEdit::OnOK() 
{CPictureList* plist=((CPictureList*)GetParent());
BYTE id=plist->objectid;
CMoinorCentreApp* pmon=((CMoinorCentreApp*)(AfxGetApp()));

if(minsize==0)
AfxMessageBox("请指定要检测目标的最小轮廓");
if(!pmon->ckbj.m_hDib)
AfxMessageBox("请指定参考背景");
if(minsize && pmon->ckbj.m_hDib)
	{pmon->alarmst[id].alramtype=1;
pmon->alarmst[id].onoff=TRUE;
m_brush.DeleteObject();
	GetParent()->KillTimer(1);
	DestroyWindow();
}
	

}

void CPicEdit::OnCancel() 
{
		// TODO: Add extra cleanup here'
GetParent()->KillTimer(1);
	DestroyWindow();

}

HBRUSH CPicEdit::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
if(nCtlColor==CTLCOLOR_DLG)
           {
              return m_brush;
           }
	if(nCtlColor == CTLCOLOR_STATIC)
	{	pDC->SetBkMode(0);
		pDC->SetTextColor(RGB(255,100,70));
hbr = (HBRUSH)::GetStockObject(NULL_BRUSH);
	return hbr;
	}	
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

BOOL CPicEdit::OnInitDialog() 
{      CRect rec;
	GetDlgItem(IDC_PICTURE)->GetWindowRect(rec);
       ScreenToClient(&rec);
	   int width=((CPictureList*)GetParent())->dibview.GetWidth();
	   int height=((CPictureList*)GetParent())->dibview.GetHeight();
   GetDlgItem(IDC_PICTURE)->MoveWindow(rec.TopLeft().x,rec.TopLeft().y,width,height);
GetDlgItem(IDC_OBJECT)->GetWindowRect(rec);
       ScreenToClient(&rec);
 GetDlgItem(IDC_OBJECT)->MoveWindow(rec.TopLeft().x,rec.TopLeft().y,320,240);
	CDialog::OnInitDialog();
	tuzhang=FALSE;
	CDib beijing;
	 beijing.Load(".//res//dd.bmp");
	 CRect ff;
GetWindowRect(ff);
beijing.ChangeImageSize(ff.Width(),ff.Height());
  m_brush.CreateDIBPatternBrush(beijing.m_hDib,DIB_PAL_COLORS);
GetDlgItem(IDC_OBJECT)->GetWindowRect(object);
objectscreen=object;
ScreenToClient(&object);
CDC* pdc=GetDC();
pdc->FillSolidRect(object,RGB(255,255,255));
ReleaseDC(pdc);
minsize=0;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPicEdit::OnTuzhang() 
{
tuzhang=TRUE;	
}

BOOL CPicEdit::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
//if(pWnd->GetDlgCtrlID()==IDC_PICTURE)
//{
	if(tuzhang)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_TUZHANG));
return true;
}


//}
	return CDialog::OnSetCursor(pWnd, nHitTest, message);
}

void CPicEdit::OnLButtonDown(UINT nFlags, CPoint point) 
{  UINT kk=nFlags;
//CString str;
//str.Format("nFlags=%d",kk);
//AfxMessageBox(str);
	// TODO: Add your message handler code here and/or call default
if(tuzhang)
{
	if(kk==9)
	{
      srcpoint=point;
	  srcselect=TRUE;
	  
	}
	if(srcselect==FALSE)
	{AfxMessageBox("不能使用仿制图章工具因为要复制的区域还没定义(按住ctrl键点按定义源点)");
	}
	else
	{dstpoint=point;
	}
}    

switch(drawtype)
{
case 1:	{if(point.x>object.TopLeft().x  && point.y>object.TopLeft().y
	 && point.x<object.BottomRight().x && point.y<object.BottomRight().y)
		{
      rectop=point;
      rectopsel=TRUE;
      first=1;
	  break;
		}
		}
case 2:{if(point.x>object.TopLeft().x  && point.y>object.TopLeft().y
	 && point.x<object.BottomRight().x && point.y<object.BottomRight().y)
	   {linepoint=point;
	    CDC* pdc=GetDC();
		pdc->FillSolidRect(object,RGB(255,255,255));
		ReleaseDC(pdc);
	   }
	break;
	   }
}
	CDialog::OnLButtonDown(nFlags, point);
}

void CPicEdit::OnMouseMove(UINT nFlags, CPoint point) 
{
if(nFlags==MK_LBUTTON )
{
if(srcselect==TRUE && tuzhang)
	{CDC* pdc=GetDC();
		CPoint offset=point-dstpoint;
		CPoint src=srcpoint+offset;
		 COLORREF clolor;
		for(int i=-2;i<=2;i++)
		{for(int j=-2;j<=2;j++)
			{int x=src.x+i;
				int y=src.y+j;
				int xdst=point.x+i;
				int ydst=point.y+j;
				clolor=pdc->GetPixel(x,y); 
				pdc->SetPixel(xdst,ydst,clolor);
			}
		 }
	ReleaseDC(pdc); 
		}

		if(drawtype==1 && rectopsel)
		{
			CRect rec;
			rec.SetRect(rectop,point);
			CDC* pdc=GetDC();
			pdc->FillSolidRect(object,RGB(255,255,255));
			pdc->Rectangle(rec);
			ReleaseDC(pdc);
		}	

    if (drawtype==2)
	 {if(point.x>object.TopLeft().x  && point.y>object.TopLeft().y
	   && point.x<object.BottomRight().x && point.y<object.BottomRight().y)
	 {CDC* pdc=GetDC();
	   	//for(int i=-1;i<=1;i++)
		//{for(int j=-1;j<=1;j++)
			//{	int xdst=point.x+i;
			//	int ydst=point.y+j;			
			//	pdc->SetPixel(xdst,ydst,RGB(0,0,0));
			//}
		 //}
	pdc->MoveTo(linepoint);
	pdc->LineTo(point);
		linepoint=point;
	   ReleaseDC(pdc);
	 }
	 }

}
	CDialog::OnMouseMove(nFlags, point);
}

void CPicEdit::OnSave() 
{		CRect  rec;

//CFileDialog dlg(FALSE,"bmp","*.bmp");
	//if(dlg.DoModal() == IDOK)
	//{	 	
	//CString strPathName;   
	//strPathName = dlg.GetPathName(); 
//bkdib.Save(strPathName);
	//}
CPictureList* plist=((CPictureList*)GetParent());
//CDectectSet* pdect=((CDectectSet*)(plist->GetParent)());
CMoinorCentreApp* pmon=((CMoinorCentreApp*)(AfxGetApp()));
BYTE id=plist->objectid;


HDIB mdib=CopyHandle(((CPictureList*)GetParent())->dibview.m_hDib);
pmon->ckbj.Destroy();
pmon->ckbj.Attach(mdib);
pmon->ckbj.ChangeToGray();
pmon->ckbj.Display(GetDC(),48,200);
}

void CPicEdit::OnRectange() 
{
drawtype=1;	
}

void CPicEdit::OnPen() 
{
drawtype=2;	
}

void CPicEdit::OnLButtonUp(UINT nFlags, CPoint point) 
{if(drawtype==1)
{
rectopsel=FALSE;
CRect rec;
rec.SetRect(rectop,point);
//this->Invalidate();
CDC* pdc=GetDC();



ReleaseDC(pdc);
}
	CDialog::OnLButtonUp(nFlags, point);
}

void CPicEdit::OnOk() 
{
CDib lunkuo;	// TODO: Add your control notification handler code here
lunkuo.Create(objectscreen);
lunkuo.ChangeToGray();
LPBYTE lpData=lunkuo.GetBitsPtr();
int lWidth=lunkuo.GetWidth();
int lHeight=lunkuo.GetHeight();
tr* trsu=new tr[10];
lunkuo.Save("objec.bmp");
int num=TraceDIB(lpData, lWidth,lHeight,5,trsu);
CString kk;

int lnum=trsu[0].edgenum;

delete trsu;

//CPictureList* plist=((CPictureList*)GetParent());
//BYTE id=plist->objectid;
//kk.Format("num=%d,lnum=%d,id=%d",num,lnum,id);
//AfxMessageBox(kk);
//CMoinorCentreApp* pmon=((CMoinorCentreApp*)(AfxGetApp()));

//pmon->alarmst[id].objectminsize=lnum;
minsize=lnum;
}

void CPicEdit::OnFinish() 
{

}

⌨️ 快捷键说明

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