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

📄 staticdlg.cpp

📁 这是一个采集图像界面
💻 CPP
字号:
// StaticDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Static.h"
#include "StaticDlg.h"
#include "DlgReplay.h"
#include "DlgSingle.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

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()

/////////////////////////////////////////////////////////////////////////////
// CStaticDlg dialog

CStaticDlg::CStaticDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStaticDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStaticDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_exposureT=1000;
	m_lineTime=1000;

	m_singleGrab=true;
	m_continuouslyGrab=true;
	m_grabSave=true;

	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

void CStaticDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStaticDlg)
	DDX_Control(pDX, IDC_COMBOEXPTIME, m_exposureTime);
	DDX_Control(pDX, IDC_COMBOLINEP, m_linePeriod);
	DDX_Control(pDX, IDC_EDIT4, m_editWindow);
	DDX_Control(pDX, IDC_SLIDERREF, m_sliderRef);
	DDX_Control(pDX, IDC_SLIDERGAIN, m_sliderGain);
	DDX_Control(pDX, IDC_DISPWINDOW, m_dispWindow);
	//}}AFX_DATA_MAP
}
//CStaticDlg::~CStaticDlg(CWnd* pParent = NULL)
//{
//}
BEGIN_MESSAGE_MAP(CStaticDlg, CDialog)
	//{{AFX_MSG_MAP(CStaticDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OK, OnOk)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDERGAIN, OnCustomdrawSlidergain)
	ON_BN_CLICKED(IDC_QUIT, OnQuit)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDERREF, OnCustomdrawSliderref)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDERGAIN, OnReleasedcaptureSlidergain)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDERREF, OnReleasedcaptureSliderref)
	ON_BN_CLICKED(IDC_REPLAYCONTINUOUSLY, OnReplaycontinuously)
	ON_BN_CLICKED(IDC_REPLAYSINGLE, OnReplaysingle)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_SINGLE, OnSingle)
	ON_BN_CLICKED(IDC_CONTINUE, OnContinue)
	ON_BN_CLICKED(IDC_ZENGLIANG, OnZengliang)
	ON_BN_CLICKED(IDC_JUNHENG, OnJunheng)
	ON_BN_CLICKED(IDC_ERZHIHUA, OnErzhihua)
	ON_CBN_SELCHANGE(IDC_COMBOEXPTIME, OnSelchangeComboexptime)
	ON_CBN_SELCHANGE(IDC_COMBOLINEP, OnSelchangeCombolinep)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStaticDlg message handlers

BOOL CStaticDlg::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);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			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

	//各种初始化
	ShowWindow(SW_SHOWMAXIMIZED);

	m_dispWindow.MoveWindow(300,50,800,500,FALSE);

	m_sliderGain.SetRange(0,50);
	m_sliderGain.SetPageSize(10);
	m_sliderGain.SetPos(20);

	m_sliderRef.SetRange(0,10);
	m_sliderRef.SetPageSize(2);
	m_sliderRef.SetPos(3);

	m_linePeriod.AddString("500");
    m_linePeriod.AddString("800");
    m_linePeriod.AddString("1000");
    m_linePeriod.AddString("1500");
    m_linePeriod.AddString("2000");
    m_linePeriod.SetCurSel(2);

	m_exposureTime.AddString("500");
	m_exposureTime.AddString("800");
	m_exposureTime.AddString("1000");
	m_exposureTime.AddString("1500");
	m_exposureTime.AddString("2000");
	m_exposureTime.SetCurSel(2);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CStaticDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	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 CStaticDlg::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);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CStaticDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

//屏蔽回车键的实现
void CStaticDlg::OnOk() 
{
	// TODO: Add your control notification handler code here

}

//增益静态框显示的捕获
void CStaticDlg::OnCustomdrawSlidergain(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	m_gainValue=m_sliderGain.GetPos();
	itoa(m_gainValue,m_gainStr,10);
    GetDlgItem(IDC_STATICGAIN)->SetWindowText(m_gainStr);
	*pResult = 0;
}

//系统退出
void CStaticDlg::OnQuit() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnOK();
}

//参考电平静态框显示的捕获
void CStaticDlg::OnCustomdrawSliderref(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	m_refValue=m_sliderRef.GetPos();
	itoa(m_refValue,m_refStr,10);
	GetDlgItem(IDC_STATICREF)->SetWindowText(m_refStr);
	*pResult = 0;
}

//增益参数的调整实现,在此函数中传递
void CStaticDlg::OnReleasedcaptureSlidergain(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	MessageBox(m_gainStr,"增益");
	//::MessageBox(this,m_gainStr,"增益",MB_OK);
	*pResult = 0;
}

//参考电平参数的调整实现,在此函数中传递
void CStaticDlg::OnReleasedcaptureSliderref(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	MessageBox(m_refStr,"参考电平");
	*pResult = 0;
}

//响应复合框选择的变化,在此中传递“线周期”参数
void CStaticDlg::OnSelchangeCombolinep() 
{
	// TODO: Add your control notification handler code here
	int i=m_linePeriod.GetCurSel();
	m_linePeriod.GetLBText(i,m_strLineP);
	m_lineTime=atoi(m_strLineP);

	if(m_lineTime >= m_exposureT)
	{
		MessageBox("OK");
	    //MessageBox(m_strLineP);
		CString strtemp(m_strLineP);
		CString str2;
		str2="线周期:"+strtemp; 
		MessageBox(str2,"线周期");
	}
	else 
	{
		MessageBox("错误,线周期应该大于曝光时间");
	}
}


//响应复合框选择的变化,在此中传递“曝光时间”参数
void CStaticDlg::OnSelchangeComboexptime() 
{
	// TODO: Add your control notification handler code here

	int i=m_exposureTime.GetCurSel();
	m_exposureTime.GetLBText(i,m_strExposureT);
	
	m_exposureT=atoi(m_strExposureT);
	
	if(m_lineTime >= m_exposureT)
	{
		MessageBox("OK");
		//CString strTemp;
		//CString strTemp2(m_strExposureT);
		//strTemp="曝光时间"+strTemp2;
		//MessageBox("曝光时间:"+m_strExposureT);
		//MessageBox(strTemp);
		CString strtemp(m_strExposureT);//这样可以把数组里的字符赋值到CString对象中。
		CString str2;
		str2="曝光时间:"+strtemp;       //一种更明白显示的方法!!!
		//MessageBox(strtemp);
		MessageBox(str2,"曝光时间");
	}
	else 
	{
		MessageBox("错误,曝光时间应该小于线周期");
	}
}


//单采
void CStaticDlg::OnSingle() 
{
	// TODO: Add your control notification handler code here
	if(m_singleGrab==true)
	{
	  m_singleGrab=false;
	  SetDlgItemText(IDC_SINGLE,"停止单采");
	  GetDlgItem(IDC_CONTINUE)->EnableWindow(FALSE);
	  GetDlgItem(IDC_SAVE)->EnableWindow(FALSE);
	}
	else
	{
		m_singleGrab=true;
		SetDlgItemText(IDC_SINGLE,"开始单采");
		GetDlgItem(IDC_CONTINUE)->EnableWindow(TRUE);
		GetDlgItem(IDC_SAVE)->EnableWindow(TRUE);
	}
}


//连采
void CStaticDlg::OnContinue() 
{
	// TODO: Add your control notification handler code here
	if(m_continuouslyGrab==true)
	{
	  m_continuouslyGrab=false;
	  SetDlgItemText(IDC_CONTINUE,"停止连采");
	  GetDlgItem(IDC_SINGLE)->EnableWindow(FALSE);
	  GetDlgItem(IDC_SAVE)->EnableWindow(FALSE);
	}
	else
	{
		m_continuouslyGrab=true;
		SetDlgItemText(IDC_CONTINUE,"开始连采");
		GetDlgItem(IDC_SINGLE)->EnableWindow(TRUE);
		GetDlgItem(IDC_SAVE)->EnableWindow(TRUE);
	}
}


//采集并存储,需要从其对话框中获取存储标识符,并判断是否为空
void CStaticDlg::OnSave() 
{
	// TODO: Add your control notification handler code here
	//CDlgSingle DlgSave;
	//GetDlgItem(IDC_STATICBIAOSHI)->SetWindowText("存储标识符");
	//DlgSave.DoModal();
	//(this->GetDlgItem(IDC_STATICBIAOSHI))->SetWindowText("存储标识符");

	if(m_grabSave==true)
	{
	  m_grabSave=false;
	  SetDlgItemText(IDC_SAVE,"停止采存");
	  GetDlgItem(IDC_SINGLE)->EnableWindow(FALSE);
	  GetDlgItem(IDC_CONTINUE)->EnableWindow(FALSE);
	}
	else
	{
		m_grabSave=true;
		SetDlgItemText(IDC_SAVE,"开始采存");
		GetDlgItem(IDC_SINGLE)->EnableWindow(TRUE);
		GetDlgItem(IDC_CONTINUE)->EnableWindow(TRUE);
	}
}


//连续回放,从连续回放编辑框中获取要回放的开始、结束帧数,并判断是否非法
void CStaticDlg::OnReplaycontinuously() 
{
	// TODO: Add your control notification handler code here
	CDlgReplay DlgReplay;
	DlgReplay.DoModal();
	//MessageBox("正在回放");

}


//单帧回放
void CStaticDlg::OnReplaysingle() 
{
	// TODO: Add your control notification handler code here
	//CDlgSingle DlgSingle;
	//DlgSingle.Create("单帧回放");
	//DlgSingle.DoModal();
    MessageBox("正在回放...帧");
}


//图像变亮
void CStaticDlg::OnZengliang() 
{
	// TODO: Add your control notification handler code here
	
}


//图像均衡化
void CStaticDlg::OnJunheng() 
{
	// TODO: Add your control notification handler code here
	
}


//二值化实现
void CStaticDlg::OnErzhihua() 
{
	// TODO: Add your control notification handler code here
	
}






⌨️ 快捷键说明

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