?? 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;
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");
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 + -