📄 痴迷人信号采集系统dlg.cpp
字号:
// 痴迷人信号采集系统Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "ua300.h"
#include <iostream.h>
#include <fstream.h>
#include "痴迷人信号采集系统.h"
#include "痴迷人信号采集系统Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_NOTIFYICON WM_USER+1
#define IDC_NOTIFYICON WM_USER+2
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CHyperLink m_mail;
CHyperLink m_site;
//}}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
m_site.SetURL(_T("http://www.laohan213.net"));
m_mail.SetURL(_T("mailto:laohan213@163.com"));
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_EMAIL, m_mail);
DDX_Control(pDX, IDC_SITE, m_site);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
hBlackBrush = CreateSolidBrush(RGB(0,0,0));
hRedPen = CreatePen(PS_SOLID,1,RGB(255,0,0));
hYellowPen = CreatePen(PS_SOLID,1,RGB(128,128,0));
hBlackPen = CreatePen(PS_SOLID,1,RGB(0,0,0));
m_uRate = 50000;
m_fVolt = 5;
m_iChanels = 1;
m_bIsStarted= false;
m_bIsDrawGraph = false;
m_bIsDrawFFT = false;
m_bMinimize = false;
for(int i=0;i<SCANCOUNT;i++)
{
addat[2*i]=0;
addat[2*i+1]=0;
fftdat[i]=0;
fftdat1[i]=0;
fftout[i]=0;
fftout1[i]=0;
fftin[i]=0;
fftin1[i]=0;
}
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_FFT, m_btFFT);
DDX_Control(pDX, IDC_LOAD, m_btLoad);
DDX_Control(pDX, IDC_SAVE, m_btSave);
DDX_Control(pDX, IDC_STOP, m_btStop);
DDX_Control(pDX, IDC_START, m_btStart);
DDX_Control(pDX, IDC_VOLT, m_combVolt);
DDX_Control(pDX, IDC_RATE, m_combRate);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_SHOW, OnShow)
ON_BN_CLICKED(ID_EXIT, OnExit)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_START, OnStart)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(ID_MINIMIZE, OnMinimize)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_BN_CLICKED(IDC_LOAD, OnLoad)
ON_BN_CLICKED(IDC_FFT, OnFft)
ON_CBN_SELCHANGE(IDC_VOLT, OnSelchange)
ON_MESSAGE(WM_NOTIFYICON,OnWM_NOTIFYICON)
ON_BN_CLICKED(ID_ABOUT, OnAbout)
ON_CBN_SELCHANGE(IDC_RATE, OnSelchange)
ON_BN_CLICKED(IDC_Chanel, OnChanelchange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowText("痴迷人信号采集系统V1.0");
// 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
//::SetWindowPos(m_hWnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
::EnableWindow(m_btFFT,false);
m_combRate.InsertString(0,_T("10"));
m_combRate.InsertString(1,_T("20"));
m_combRate.InsertString(2,_T("30"));
m_combRate.InsertString(3,_T("40"));
m_combRate.InsertString(4,_T("50"));
m_combRate.InsertString(5,_T("60"));
m_combRate.InsertString(6,_T("70"));
m_combRate.InsertString(7,_T("80"));
m_combRate.InsertString(8,_T("90"));
m_combRate.InsertString(9,_T("100"));
m_combRate.InsertString(10,_T("110"));
m_combRate.InsertString(11,_T("120"));
m_combRate.InsertString(12,_T("130"));
m_combRate.InsertString(13,_T("140"));
m_combRate.InsertString(14,_T("150"));
m_combRate.InsertString(15,_T("160"));
m_combRate.InsertString(16,_T("170"));
m_combRate.InsertString(17,_T("180"));
m_combRate.InsertString(18,_T("190"));
m_combRate.InsertString(19,_T("200"));
m_combRate.SetCurSel(4);
m_combVolt.InsertString(0,_T("10"));
m_combVolt.InsertString(1,_T("5"));
m_combVolt.InsertString(2,_T("2.5"));
m_combVolt.InsertString(3,_T("1.25"));
m_combVolt.InsertString(4,_T("0.625"));
m_combVolt.SetCurSel(1);
this->GetClientRect(&rect);
rectBig.left = rect.left+10;
rectBig.right= rect.right-140;
rectBig.top = rect.top+10;
rectBig.bottom=rect.bottom-10;
rectSmall.left = rectBig.left+80;
rectSmall.top = rectBig.top+10;
rectSmall.right= rectSmall.left+512;
rectSmall.bottom=rectBig.bottom;
rectArea3.left =0;
rectArea3.right =0;
rectArea3.top =0;
rectArea3.bottom=0;
rectArea4.left =0;
rectArea4.right =0;
rectArea4.top =0;
rectArea4.bottom=0;
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::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 CMyDlg::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();
DrawArea();
if(m_bIsDrawGraph)
DrawGraph();
if(m_bIsDrawFFT)
DrawFFT();
}
//添加任务栏图标
NOTIFYICONDATA nc;
nc.cbSize = sizeof(NOTIFYICONDATA);
nc.hIcon = m_hIcon;
nc.hWnd = m_hWnd;
lstrcpy(nc.szTip,"痴迷人信号采集系统 1.0 版");
nc.uCallbackMessage = WM_NOTIFYICON;
nc.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nc.uID = IDC_NOTIFYICON;
Shell_NotifyIcon(NIM_ADD, &nc);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CMyDlg::OnCancel()
{
// TODO: Add extra cleanup here
//CDialog::OnCancel();
ShowWindow(SW_HIDE);
m_bMinimize = true;
}
void CMyDlg::OnExit()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
void CMyDlg::OnWM_NOTIFYICON(WPARAM wParam, LPARAM lParam)
{
UINT nID = (UINT)wParam;
UINT uMouseMsg = (UINT)lParam;
switch(uMouseMsg)
{
case WM_LBUTTONDBLCLK:
if(m_bMinimize = true)
{
ShowWindow(SW_SHOW);
m_bMinimize = false;
break;
}
else
{
ShowWindow(SW_HIDE);
m_bMinimize = true;
break;
}
case WM_RBUTTONDOWN:
CMenu menu;
CPoint curpos;
GetCursorPos(&curpos);
if(menu.LoadMenu(IDR_NOTIFY_MENU))
{
CMenu* pPopup;
pPopup=menu.GetSubMenu(0);
ASSERT(pPopup!=NULL);
SetForegroundWindow();
pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,curpos.x,curpos.y,AfxGetMainWnd());
}
}
}
void CMyDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
NOTIFYICONDATA nc;
nc.cbSize = sizeof(NOTIFYICONDATA);
nc.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
nc.hWnd = m_hWnd;
nc.uCallbackMessage = WM_NOTIFYICON;
nc.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nc.uID = IDC_NOTIFYICON;
Shell_NotifyIcon(NIM_DELETE, &nc);
}
void CMyDlg::OnShow()
{
ShowWindow(SW_SHOW);
m_bMinimize = false;
}
void CMyDlg::OnStart()
{
// TODO: Add your control notification handler code here
DrawArea();
m_bIsStarted=true;
m_bIsDrawGraph=true;
m_bIsDrawFFT=false;
::EnableWindow(m_btLoad,false);
::EnableWindow(m_btFFT,true);
SetTimer(1,1000,NULL);//设置定时器
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -