
// MeterDlg.h : header file
//

#pragma once
#include "afxwin.h"
#include "StaticLCD.h"
#include "afxcmn.h"
#include "MeterParam.h"
#include "DlgDevList.h"
#include <time.h>

#include <deque>
using namespace std;

// CMeterDlg dialog
class CMeterDlg : public CDialogEx
{
// Construction
public:
	CMeterDlg(CWnd* pParent = NULL);	// standard constructor
public:
	HANDLE m_hEvent;
	HANDLE m_hThreadProc;
	int	m_lastid;
	int m_matches;
	time_t m_tLastMatch;
	CString m_strWriteFileName;
	BOOL m_bWriteData;

protected:
	CMeterParam m_DMM;
	deque<HTMSG> m_msgDeque;
	BOOL m_bComConnect;
public:
	void InitDevice();
	void Run();
	void GetDMMData();
	HTMSG GetCmdMsg();
	void CmdMsgProc(HTMSG msg);
	void PushCmdMsg(HTMSG msg);
	void SetDMMType(short nType);
	void SetDMMACDC();
	void SetDMMAutoManual();
	void SetDMMRel();
	void SetDMMDIV();
	void SetDMMAmA();
	void ClearData();
	void SaveData();
	void WriteData();
	void InitListCtrl();
	void SetCtrlsText();
	void ShowCtrls();
	void SetListData();
protected:
	void UserExitThread();
public:
	static DWORD WINAPI DMMProc(LPVOID lParam);

public:
// Dialog Data
	enum { IDD = IDD_METER_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
	void OnOk();
	BOOL CMeterDlg::PreTranslateMessage(MSG* pMsg);
public:
	afx_msg void OnDestroy();
	afx_msg void OnBnClickedBtnV();
	afx_msg void OnBnClickedBtnA();
	afx_msg void OnBnClickedBtnOhm();
	afx_msg void OnBnClickedBtnCap();
	afx_msg void OnBnClickedBtnDiode();
	afx_msg void OnBnClickedBtnConti();
	afx_msg void OnBnClickedBtnAcdc();
	afx_msg void OnBnClickedBtnAutomanual();
	afx_msg void OnBnClickedBtnRel();
	afx_msg void OnBnClickedBtnAma();
	afx_msg void OnBnClickedBtnDiv();
	afx_msg void OnBnClickedBtnClear();
	afx_msg void OnBnClickedBtnSave();
	afx_msg void OnBnClickedBtnRun();
	afx_msg void OnCbnSelchangeCboInterval();
	afx_msg void OnBnClickedBtnHelp();
public:
	CStaticLCD m_stcLCD;
	CButton m_btnV;
	CButton m_btnA;
	CButton m_btnOHM;
	CButton m_btnC;
	CButton m_btnD;
	CButton m_btnConti;
	CButton m_btnACDC;
	CButton m_btnAutoManual;
	CButton m_btnRel;
	CButton m_btnAmA;
	CButton m_btnDIV;
	CEdit m_editWavFile;
	CEdit m_editCommand;
	CEdit m_from;
	CEdit m_to;
	CButton m_checkRepeat;
	CButton m_checkAlarmEnabled;
	CListCtrl m_listData;
	CComboBox m_cboInterval;
	CButton m_btnRunStop;
	CButton m_btnClearData;
	CButton m_btnSaveData;
	CButton m_rdoUSB;
	CButton m_rdoCOM;
	afx_msg void OnBnClickedRadioUsb();
	afx_msg void OnBnClickedRadioCom();
	CComboBox m_cboCOMPort;
	CStatic m_stcCOMPort;
	CStatic m_stcFilename;
	afx_msg void OnCbnSelchangeCboComport();
	CButton m_btnConnect;
	CButton m_chkAutoscroll;
	CStatic m_stcMatchCounter;
	CEdit m_editDelay;
	CButton m_chkShowLog;

	afx_msg void OnBnClickedBtnConnect();
	afx_msg void OnBnClickedBtnSave3();
	afx_msg void OnBnClickedCheck1();
	afx_msg void OnLvnItemchangedListData(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedButton1();
	afx_msg void OnBnClickedButton2();
	afx_msg void OnBnClickedButton3();
	afx_msg void OnBnClickedCheckrep();
};
