?? carlpdlg.cpp
字號:
// CarLPDlg.cpp : 實現文件
//
#include "stdafx.h"
#include "CarLP.h"
#include "CarLPDlg.h"
#include "ProcessDlg.h"
#include "HistogramDlg.h"
#include "HelpDlg.h"
#include ".\carlpdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于應用程序“關于”菜單項的 CAboutDlg 對話框
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCarLPDlg dialog
//
//CCarLPDlg constructor
CCarLPDlg::CCarLPDlg(CWnd* pParent /*=NULL*/): CDialog(CCarLPDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDIPDemoDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
buttonptr=0;
menufocus=-1;
lpBitmap=0;
lpBackup=0;
// Grabbing=FALSE;
lpPoints=0;
}
//Called by the framework to exchange and validate dialog data
void CCarLPDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDIPDemoDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
#define WM_BUTTONCLICK WM_USER+10000 //用戶自定義消息
BEGIN_MESSAGE_MAP(CCarLPDlg, CDialog)
//{{AFX_MSG_MAP(CCarLPDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_MESSAGE(WM_BUTTONCLICK,OnClick)
ON_WM_LBUTTONDBLCLK()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCarLPDlg message handlers
#define BUTTON_LEFT1 370
#define BUTTON_LEFT2 510
#define BUTTON_LEFT3 650
enum {
INPUT_FILE, INPUT_GRAB,
INPUT_SNAP, INPUT_SCAN,
INPUT_PASTE, INPUT_RESTORE,
NOCOLOR, NOISE_GAUSSIAN,
NOISE_PEPPER, HISTOEQ,
HISTOSHOW, SMOOTH,
EDGE, PSEUDOCOLOR,
BRIGHTMODIFY, BIVALUE,
GEOMETRICAL, TRANSFORM,
OUTPUT_SAVEAS, OUTPUT_PRINT,
OUTPUT_COPY
};
BOOL CCarLPDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);//Allows the application to access the
//Control menu for copying and modification
if (pSysMenu != NULL)
{
CString strAboutMenu;
//Reads a Windows string resource, identified by nID, into an existing CStringT object
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR); //Appends a new item to the end of a menu
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
SetWindowText("Car License Recognition System");
//開頭圖片
CSplashWnd::EnableSplashScreen();
CSplashWnd::ShowSplashScreen(this);
//add the button
//圖像輸入
AddButton(BUTTON_LEFT1,120,INPUT_FILE,"打開文件");
AddButton(BUTTON_LEFT2+30,120,INPUT_GRAB,"∮pdx+qdy=∫∫()dxdy");
//AddButton(BUTTON_LEFT3,120,INPUT_SNAP,"捕捉圖像");
AddButton(BUTTON_LEFT1,160,INPUT_PASTE,"從剪貼板粘貼");
AddButton(BUTTON_LEFT2,160,INPUT_SCAN,"打開掃描軟件");
AddButton(BUTTON_LEFT3,160,NOCOLOR,"去除彩色");
AddButton(BUTTON_LEFT1,200,NOISE_GAUSSIAN,"隨機噪聲");
AddButton(BUTTON_LEFT2,200,NOISE_PEPPER,"椒鹽噪聲");
AddButton(BUTTON_LEFT3,200,INPUT_RESTORE,"恢復原始圖像");
//圖像處理
AddButton(BUTTON_LEFT1,300,GEOMETRICAL,"幾何變換");
AddButton(BUTTON_LEFT2,300,BRIGHTMODIFY,"灰度反轉");
AddButton(BUTTON_LEFT3,300,HISTOEQ,"直方圖均衡化");
AddButton(BUTTON_LEFT1,340,HISTOSHOW,"直方圖統計");
AddButton(BUTTON_LEFT2,340,SMOOTH,"圖像復原");
AddButton(BUTTON_LEFT3,340,EDGE,"邊緣提取");
AddButton(BUTTON_LEFT1,380,PSEUDOCOLOR,"偽彩色");
AddButton(BUTTON_LEFT2,380,BIVALUE,"二值化");
AddButton(BUTTON_LEFT3,380,TRANSFORM,"圖像變換");
//圖像輸出
AddButton(BUTTON_LEFT1,480,OUTPUT_SAVEAS,"另存為...");
AddButton(BUTTON_LEFT2,480,OUTPUT_PRINT,"打印輸出");
AddButton(BUTTON_LEFT3,480,OUTPUT_COPY,"復制到剪貼板");
AddButton(370,530,-3,"Hough transform");
AddButton(BUTTON_LEFT2,530,-2,"最小化");
AddButton(BUTTON_LEFT3,530,-1,"退出系統");
//Creates a Windows child window and attaches it to the CWnd object or its sucessive object
source.Create(0,"Source",WS_CHILD|WS_VISIBLE,CRect(20,20,340,260), this, 10000);
// source.SetScroll(360,280);
dest.Create(0,"Destination",WS_CHILD|WS_VISIBLE,CRect(20,310,340,550), this, 10001);
// dest.SetScroll(360,280);
ShowWindow(SW_SHOWNORMAL);//| SW_MINIMIZESW_MAXIMIZE
return TRUE; // return TRUE unless you set the focus to a control
}
#define VHIBUTTON RGB(0,0,240)
#define HIBUTTON RGB(0,0,220)
#define LOBUTTON RGB(0,0,128)
#define BUTTON RGB(0,0,160)
/*
#define VHIBUTTON RGB(240,220,160)
#define HIBUTTON RGB(220,200,150)
#define LOBUTTON RGB(128,110,70)
#define BUTTON RGB(160,140,100)
*/
/*
#define VHIBUTTON RGB(0,220,220)
#define HIBUTTON RGB(0,200,200)
#define LOBUTTON RGB(0,128,128)
#define BUTTON RGB(0,160,160)
*/
//display the buttons on the panel
void DrawButton(CDC *pDC,int x0,int y0,int state,const char *caption,int buttonPtr)
{
if(buttonPtr != 1)
{
//fill the button,buttonPtr,with the color HIBUTTON or BUTTON
pDC->FillSolidRect(x0,y0,120,24,state?HIBUTTON:BUTTON);
if (state==0)
pDC->Draw3dRect(x0,y0,120,24,HIBUTTON,LOBUTTON);
else if (state==1)
pDC->Draw3dRect(x0,y0,120,24,VHIBUTTON,LOBUTTON);
else
pDC->Draw3dRect(x0,y0,120,24,BUTTON,BUTTON);
//to draw the caption of the buttonPtr on the panel
CSize sz=pDC->GetTextExtent(caption);
pDC->SetBkColor(state?HIBUTTON:BUTTON);// Sets the background color of the list view control
pDC->SetTextColor(state?RGB(255,255,255):RGB(220,220,240));
if (state==2)
pDC->TextOut(x0+61-sz.cx/2,y0+4,caption);
else
pDC->TextOut(x0+60-sz.cx/2,y0+3,caption);
}
else//buttonPtr == 1)
{
pDC->FillSolidRect(x0,y0,190,30,state?HIBUTTON:BUTTON);
if (state==0)
pDC->Draw3dRect(x0,y0,190,30,HIBUTTON,LOBUTTON);
else if (state==1)
pDC->Draw3dRect(x0,y0,190,30,VHIBUTTON,LOBUTTON);
else
pDC->Draw3dRect(x0,y0,190,30,BUTTON,BUTTON);
CSize sz=pDC->GetTextExtent(caption);
pDC->SetBkColor(state?HIBUTTON:BUTTON);
pDC->SetTextColor(state?RGB(0,255,0):RGB(255,255,0));
if (state==2)
pDC->TextOut(x0+90-sz.cx/2,y0+4,caption);
else
pDC->TextOut(x0+88-sz.cx/2,y0+3,caption);
}
}
void CCarLPDlg::OnSysCommand(UINT nID, LPARAM lParam) //give response to the about dialog
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCarLPDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);//Copies the client coordinates of the CWnd client area
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this);
int i;
for(i=0;i<buttonptr;i++)
{
DrawButton(&dc,buttonx[i],buttony[i],0,buttoncaption[i],i);
}
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCarLPDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
/*
#define HIYELLOW RGB(230,200,120)
#define YELLOW RGB(180,160,100)
#define LOYELLOW RGB(120,100,70)
*/
#define HIYELLOW RGB(160,160,160)
#define LOYELLOW RGB(80,80,80)
#define YELLOW RGB(128,128,128)
void DrawFrame(CDC *pDC, int x0,int y0,int cx,int cy)
{
pDC->FillSolidRect(x0+1,y0+1,cx+20,cy+20,YELLOW);
pDC->Draw3dRect(x0,y0,cx+22,cy+22,HIYELLOW,LOYELLOW);
pDC->Draw3dRect(x0+9,y0+9,cx+2,cy+2,LOYELLOW,HIYELLOW);
//pDC->FillSolidRect(x0+11,y0+11,cx,cy,RGB(160,140,120));
}
#define HIBORDER RGB(200,80,240)
#define BORDER RGB(160,60,192)
#define LOBORDER RGB(120,40,160)
void DrawBorder(CDC *pDC, int x0,int y0,int cx,int cy,const char *caption)
{
pDC->Draw3dRect(x0,y0,cx,cy,HIBORDER,LOBORDER);
pDC->Draw3dRect(x0+1,y0+1,cx-2,cy-2,LOBORDER,HIBORDER);
pDC->FillSolidRect(x0+25,y0-18,100,19,BORDER);
pDC->Draw3dRect(x0+24,y0-19,102,21,HIBORDER,LOBORDER);
pDC->SetBkColor(BORDER);
CSize sz=pDC->GetTextExtent(caption);
pDC->TextOut(x0+76-sz.cx/2,y0-17,caption);
}
BOOL CCarLPDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CBitmap bm;
BITMAP bmi; //The BITMAP structure defines the height, width, color format, and bit values of a logical bitmap
//Load the background
bm.LoadBitmap(IDB_BACKGROUND);//load the bitmap resource identified by IDB_BACKGROUND
bm.GetBitmap(&bmi);//Call this member function to retrieve information about a CBitmap object
CDC memdc;
memdc.CreateCompatibleDC(pDC);
memdc.SelectObject(bm);
int x,y;
for(y=0;y<6;y++)//
{
for(x=0;x<8;x++)
{//Copies a bitmap from the source device context to this current device context
pDC->BitBlt(x*bmi.bmWidth,y*bmi.bmHeight,bmi.bmWidth,bmi.bmHeight,&memdc,0,0,SRCCOPY);
}
}
bm.DeleteObject();
//load the frame
bm.LoadBitmap(IDB_FRAME);
bm.GetBitmap(&bmi);
memdc.SelectObject(bm);
pDC->BitBlt(10,10,340,260,&memdc,0,0,SRCCOPY);
pDC->BitBlt(10,300,340,260,&memdc,0,0,SRCCOPY);
bm.DeleteObject();
DrawFrame(pDC,10,10,320,240);
DrawFrame(pDC,10,300,320,240);
pDC->SetTextColor(RGB(240,240,240));
pDC->SetBkMode(TRANSPARENT);
DrawBorder(pDC,BUTTON_LEFT1-10,105,420,134,"圖像輸入");
DrawBorder(pDC,BUTTON_LEFT1-10,285,420,134,"圖像處理");
DrawBorder(pDC,BUTTON_LEFT1-10,465,420,54,"圖像輸出");
//load the title
bm.LoadBitmap(IDB_TITLE);
bm.GetBitmap(&bmi);
memdc.SelectObject(bm);
pDC->BitBlt(370,20,400,41,&memdc,0,0,SRCCOPY);
bm.DeleteObject();
return TRUE;
}
// 此函數負責確定鼠標是否在某一Button范圍內!!120是Button長度,24是其寬度
int CCarLPDlg::HitTestButton(int x0, int y0)
{
int i;
for(i=0;i<buttonptr;i++)
{
if(i == 1)
{
if (x0>=buttonx[i] && y0>=buttony[i] && x0<=buttonx[i]+190 && y0<=buttony[i]+30) break;
}
else
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -