📄 myinterfacedlg.cpp
字号:
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CMyInterfaceDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标显示。
HCURSOR CMyInterfaceDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CMyInterfaceDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CRect rtWnd;
GetWindowRect(&rtWnd);
point.x=point.x-rtWnd.left;
point.y=point.y-rtWnd.top;
if(m_rtIcon.PtInRect(point))
{
AfxMessageBox("界面软件设计者:张峰 Email:zhangfeng8218163.com");
}
else
{
if(m_rtButtHelp.PtInRect(point))
{
SendMessage(WM_CLOSE);
}
else
{
if(m_rtButtExit.PtInRect(point))
{
SendMessage(WM_CLOSE);
}
else
{
if(m_rtButtMin.PtInRect(point))
{
m_ShowTitle=FALSE;
SendMessage(WM_SYSCOMMAND,SC_MINIMIZE,MAKELPARAM(point.x,point.y));
}
else
{
if(m_rtButtMax.PtInRect(point))
{
m_ShowTitle=TRUE;
if(IsZoomed())
{
SendMessage(WM_SYSCOMMAND,SC_RESTORE,MAKELPARAM(point.x,point.y));
}
else
{
SendMessage(WM_SYSCOMMAND,SC_MAXIMIZE,MAKELPARAM(point.x,point.y));
Invalidate();
}
}
else
{
if(!IsZoomed())
{
Default();
}
}
}
}
}
}
}
void CMyInterfaceDlg::OnNcMouseMove(UINT nHitTest, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDC* pDC=GetWindowDC();//获取整个窗口的设备上下文,包括菜单,标题,客户区等等。
CDC* pDisplayMemDC=new CDC;
pDisplayMemDC->CreateCompatibleDC(pDC);
CBitmap* pBitmap=new CBitmap;
CBitmap* pOldBitmap;
CRect rtWnd,rtButton;
if(pDC)
{
CString StrTemp="";
GetWindowRect(&rtWnd);
point.x=point.x-rtWnd.left;
point.y=point.y-rtWnd.top;
if(m_rtButtExit.PtInRect(point))
{
pBitmap->LoadBitmap(IDB_EXIT_FOCUS);
StrTemp=_T("关闭");
}
else
{
if(m_rtButtMin.PtInRect(point))
{
pBitmap->LoadBitmap(IDB_MIN_FOCUS);
StrTemp=_T("最小化窗口");
}
else
{
if(m_rtButtMax.PtInRect(point))
{
pBitmap->LoadBitmap(IDB_MAX_FOCUS);
if(IsZoomed())
StrTemp=_T("还原窗口");
else
{
StrTemp=_T("最大化窗口");
}
}
else
{
pBitmap->LoadBitmap(IDB_NORMAL);
}
}
}
rtButton=m_rtButtMin;
BITMAP BmpInfo;
pBitmap->GetBitmap(&BmpInfo);
pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
pDC->BitBlt(rtButton.left-6,rtButton.top-2,BmpInfo.bmWidth,BmpInfo.bmHeight,pDisplayMemDC,0,0,SRCCOPY);
pDisplayMemDC->SelectObject(pOldBitmap);
CRect ShowTipRect;
ShowTipRect=m_rtButtMin;
if(!StrTemp.IsEmpty())
{
ScreenToClient(&ShowTipRect);//把屏幕坐标转换成客户区域坐标
m_ToolTip.AddToolTip(IDD_MYINTERFACE_DIALOG,&ShowTipRect,StrTemp);
m_ToolTip.SetDelayTime(200);
}
}
ReleaseDC(pDisplayMemDC);
ReleaseDC(pDC);
delete pDisplayMemDC;
delete pBitmap;
CDialog::OnNcMouseMove(nHitTest, point);
}
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
{
CRect rtCtrl,rtWnd;
if(hwnd)
{
::GetWindowRect(hwnd,&rtCtrl);
::GetWindowRect(GetParent(hwnd),&rtWnd);
rtCtrl.OffsetRect(-rtWnd.left-3,-rtWnd.top-29);
float temp;
temp=(float)rtCtrl.left*m_WidthScale;
rtCtrl.left=(int)temp;
temp=(float)rtCtrl.top*m_HeightScale;
rtCtrl.top=(int)temp;
temp=(float)rtCtrl.right*m_WidthScale;
rtCtrl.right=(int)temp;
temp=(float)rtCtrl.bottom*m_HeightScale;
rtCtrl.bottom=(int)temp;
::MoveWindow(hwnd,rtCtrl.left,rtCtrl.top,rtCtrl.Width(),rtCtrl.Height(),TRUE);
return TRUE;
}
else
return FALSE;
}
void CMyInterfaceDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if(m_ReSizeFlag)
{
if(nType!=1)
{
CRect rtWnd;
GetWindowRect(&rtWnd);
m_WidthScale=(float)rtWnd.Width()/(float)m_OldWidth;
m_HeightScale=(float)rtWnd.Height()/(float)m_OldHeight;
m_OldWidth=rtWnd.Width();
m_OldHeight=rtWnd.Height();
HWND hWnd;
hWnd=GetSafeHwnd();
EnumChildWindows(hWnd,(WNDENUMPROC)EnumChildProc,0);
}
}
// TODO: 在此处添加消息处理程序代码
}
void CMyInterfaceDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDialog::OnMouseMove(nFlags, point);
}
//UINT_PTR CALLBACK CMyInterfaceDlg::SelFileHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
//{
// if(uiMsg==WM_INITDIALOG)
// {
// CWnd* pWnd=FromHandle(::GetParent(hdlg))->GetDlgItem(IDOK);
// ASSERT(pWnd);
// pWnd->SetWindowText(_T("确定"));
// return 1;
// }
// return 0;
//}
void CMyInterfaceDlg::OnBnClickedButton1()//打开图片并保存到数据库中
{
// TODO: 在此添加控件通知处理程序代码
//char szFilter[]=_T("图像文件 (*.jpg,*.jpeg,*.bmp,*.gif)|*.jpg;*.jpeg;*.bmp;*.gif|jpg文件|*.jpg|jpeg文件|*.jpeg|位图文件|*.bmp|gif文件|*.gif|所有文件|*.*||");
char szFilter[]=_T("图像文件 (*.bmp)|*.bmp|所有文件|*.*||");
CFileDialog selfile(TRUE, NULL, NULL, OFN_EXPLORER|OFN_ALLOWMULTISELECT,
szFilter, this);
CString strCurrentDir=_T("E:\\project pic");
char strFile[256*6]="";
selfile.m_ofn.lpstrFile=strFile;
selfile.m_ofn.nMaxFile=sizeof(strFile);
selfile.m_ofn.lpstrInitialDir=strCurrentDir;
selfile.m_ofn.lpstrTitle=_T("选择文件");
//selfile.m_ofn.lpfnHook=(LPOFNHOOKPROC)SelFileHookProc;
if(selfile.DoModal()==IDOK)
{
POSITION pos;
pos=selfile.GetStartPosition();
while(pos!=NULL)
{
CString string;
string=selfile.GetNextPathName(pos);
CDC* pDC=GetDlgItem(IDC_PIC)->GetDC();
//CDC* pDC=CWnd::FromHandle(::GetDlgItem(AfxGetMainWnd()->m_hWnd,IDC_PIC))->GetDC();
//CRect rect;
//CWnd::FromHandle(::GetDlgItem(AfxGetMainWnd()->m_hWnd,IDC_PIC))->GetWindowRect(&rect);
CBmpProc bmp;
CLapls lplas;
BOOL b=lplas.Get((char*)(LPCSTR)string);
if(b==FALSE)
return;
HBITMAP hBitmap=lplas.ColortoGrayScale(NULL);
bmp.LoadFromHbmp(hBitmap);
if(pBmp!=NULL)
{
delete pBmp;
pBmp=NULL;
pBmp=new CBmpProc;
}
else
pBmp=new CBmpProc;
pBmp->LoadFromObject(bmp);
CSize size=pBmp->Size();
m_top=m_left=0;
m_right=size.cx;
m_bottom=size.cy;
UpdateData(FALSE);
UpdateData(TRUE);
CRect rect;
GetDlgItem(IDC_PIC)->GetClientRect(&rect);
//::GetClientRect(::GetDlgItem(AfxGetMainWnd()->m_hWnd,IDC_PIC),&rect);
int isize=(size.cx>size.cy)?size.cx:size.cy;
pBmp->CalculateColor(pDC,isize); //计算原图的颜色直方图
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
pBmp->CalculateColorPair(i,j);
}
pBmp->SortColorPair();
//pBmp->CalculateColorPair(1,1);
//pBmp->CalculateColorPair(1,2);
//pBmp->CalculateColorPair(2,1);
//pBmp->CalculateColorPair(2,2);//其实在以上的4部计算中,已经形成了初步的颜色对表,在此只不过是将表中的数据从大到
////小排列出来并且祛除差值小于某一域值的颜色对,形成颜色对表
//pBmp->SortColorPair(); //颜色对表计算出来,表中的数据既是用户输入的该图像的代表特征
//pBmp->Draw(*pDC,&rect);
CPicture picshow;
picshow.ShowPic((char*)(LPCSTR)string,m_hWnd,IDC_PIC);
SourcePic=new char[string.GetLength()];
strcpy(SourcePic,(LPCSTR)string);
charlap=new char[string.GetLength()];
strcpy(charlap,(LPCSTR)string);
picInput=TRUE;
//在List列表中列出刚加入的图片
}
}
}
void CMyInterfaceDlg::OnBnClickedButton3()//显示单个图片,浏览下
{
// TODO: 在此添加控件通知处理程序代码
if(m_ListPic.GetCount()>0)
{
int i=m_ListPic.GetCurSel();
CString rString;
m_ListPic.GetText(i,rString);
char* fileName;
fileName=rString.GetBuffer(rString.GetLength());
DestPic=new char[rString.GetLength()];
strcpy(DestPic,fileName);
HWND hWnd = m_hWnd;
CPicture pic;
pic.ShowPic(fileName,hWnd,IDC_PIC_LIB);
intSD=2;
}
}
void CMyInterfaceDlg::OnLbnDblclkListPic()
{
// TODO: 在此添加控件通知处理程序代码
OnBnClickedButton5();
}
void CMyInterfaceDlg::OnBnClickedButton2()//删除数据库中的图片
{
// TODO: 在此添加控件通知处理程序代码
if(m_ListPic.GetCount()>0)
{
if(m_ListPic.GetCurSel()!=LB_ERR)
{
int i=m_ListPic.GetCurSel();
CString rString;
m_ListPic.GetText(i,rString);
m_ListPic.DeleteString(i);
if(!m_pset->IsOpen())
m_pset->Open();
m_pset->m_pDatabase->ExecuteSQL("delete * from pic where picaddr='"+rString+"'");
m_pset->Requery();
m_pset->Close();
m_ListPic.SetCurSel(0);
}
else
AfxMessageBox("请选择要删除的项目!");
}
else
AfxMessageBox("图片已经删完!");
}
void CMyInterfaceDlg::OnBnClickedButton4()//显示数据库中的所有图片
{
// TODO: 在此添加控件通知处理程序代码
CDC* pDC=m_ListPic.GetDC();
CString str;
CSize sz;
int dx=0;
int i=0;
m_ListPic.ResetContent();
if(!m_pset->IsOpen())
m_pset->Open();
if(m_pset->GetRecordCount()>0)
{
m_pset->MoveFirst();
while(!m_pset->IsEOF())
{
m_ListPic.AddString((LPCTSTR)(CString)(m_pset->m_picAddr));
m_ListPic.GetText(i,str);
sz=pDC->GetTextExtent(str);
if(sz.cx>dx)
dx=sz.cx;
m_pset->MoveNext();
i++;
}
m_ListPic.SetCurSel(0);
}
m_ListPic.ReleaseDC(pDC);
m_pset->Close();
m_ListPic.SetHorizontalExtent(dx);
}
void CMyInterfaceDlg::OnBnClickedSearch()//边缘检测
{
HWND hWnd=m_hWnd;
CLapls lplas;
/*BOOL b=lplas.Get(charlap);
if(b==FALSE)
return;*/
BOOL c=lplas.Get("c:\\median.bmp");
if(c==FALSE)
return;
//lplas.ColortoGrayScale(hWnd);
hBitmap=lplas.Go(hWnd,m_Sobel);
intSD=1;
}
void CMyInterfaceDlg::OnBnClickedButton5()//浏览上
{
// TODO: 在此添加控件通知处理程序代码
if(m_ListPic.GetCount()>0)
{
UpdateData(TRUE);
int i=m_ListPic.GetCurSel();
CString rString;
m_ListPic.GetText(i,rString);
PicFilePath=rString;
CBmpProc bmp;
CDC* pDC=GetDlgItem(IDC_PIC)->GetDC();
CRect rect;
GetDlgItem(IDC_PIC)->GetClientRect(&rect);
CLapls lplas;
BOOL b=lplas.Get((char*)(LPCSTR)rString);
if(b==FALSE)
return;
HBITMAP hBitmap=lplas.ColortoGrayScale(NULL);
bmp.LoadFromHbmp(hBitmap);
//bmp.LoadFromFile((LPCTSTR)rString);
if(pBmp!=NULL)
{
delete pBmp;
pBmp=NULL;
pBmp=new CBmpProc;
}
else
pBmp=new CBmpProc;
pBmp->LoadFromObject(bmp);
CSize size=pBmp->Size();
int isize=(size.cx>size.cy)?size.cx:size.cy;
pBmp->CalculateColor(pDC,isize); //计算原图的颜色直方图
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
pBmp->CalculateColorPair(i,j);
}
}
pBmp->SortColorPair();
//pBmp->CalculateColorPair(1,1);
//pBmp->CalculateColorPair(1,2);
//pBmp->CalculateColorPair(2,1);
//pBmp->CalculateColorPair(2,2);//其实在以上的4部计算中,已经形成了初步的颜色对表,在此只不过是将表中的数据从大到
////小排列出来并且祛除差值小于某一域值的颜色对,形成颜色对表
//pBmp->SortColorPair(); //颜色对表计算出来,表中的数据既是用户输入的该图像的代表特征
pBmp->Draw(*pDC,&rect);
CPicture picshow;
picshow.ShowPic((char*)(LPCSTR)rString,m_hWnd,IDC_PIC);
m_top=m_left=0;
m_right=size.cx;
m_bottom=size.cy;
UpdateData(FALSE);
picInput=TRUE;
/*char* fileName;
fileName=rString.GetBuffer(rString.GetLength()); */
SourcePic=new char[rString.GetLength()];
strcpy(SourcePic,(LPCSTR)rString);
charlap=new char[rString.GetLength()];
strcpy(charlap,(LPCSTR)rString);
}
}
void CMyInterfaceDlg::OnBnClickedButton6()//灰度处理
{
// TODO: 在此添加控件通知处理程序代码
//HWND hWnd=::FindWindow(NULL,"MyInterface");
HWND hWnd=AfxGetMainWnd()->m_hWnd;
CLapls lplas;
BOOL b=lplas.Get(charlap);
if(b==FALSE)
return;
hBitmap=lplas.ColortoGrayScale(hWnd);
CPicture pic;
pic.ShowPic(hBitmap,AfxGetMainWnd()->m_hWnd,IDC_PIC_LIB);
intSD=3;
picShow=FALSE;
}
void CMyInterfaceDlg::OnBnClickedFilter()//中值滤波去噪
{
// TODO: 在此添加控件通知处理程序代码
HWND hWnd=m_hWnd;
CLapls lplas;
BOOL c=lplas.Get("c:\\gray.bmp");
if(c==FALSE)
return;
hBitmap=lplas.MedianFilter(hWnd,m_filterCheck);
intSD=4;
}
void CMyInterfaceDlg::OnBnClickedCheck()
{
// TODO: 在此添加控件通知处理程序代码
if(m_filterCheck)
m_filterCheck=FALSE;
else
m_filterCheck=TRUE;
}
void CMyInterfaceDlg::OnBnClickedCheck1()
{
// TODO: 在此添加控件通知处理程序代码
if(m_Sobel)
m_Sobel=FALSE;
else
m_Sobel=TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -