?? sampledlg.cpp
字號:
// sampleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sample.h"
#include "sampleDlg.h"
#include "stdafx1.h"
#include "windows.h"
#include "stdafx1.h"
#include "ua300.h"
#include "mmsystem.h"
//////////////////////////////////////////////////////////////////////
#define twosecond 1
#define timeracc 1
void PASCAL OneMilliSecondProc(UINT wTimerID, UINT msg,DWORD dwUser,DWORD dwl,DWORD dw2);
//////////////////////////////////////////////////////////////
double par[512];
HANDLE husb;
int jishu1,jishu2,jishu3;
////////////////////////////////////////////////////////////////////////
#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()
/////////////////////////////////////////////////////////////////////////////
// CSampleDlg dialog
CSampleDlg::CSampleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSampleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSampleDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSampleDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSampleDlg, CDialog)
//{{AFX_MSG_MAP(CSampleDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSampleDlg message handlers
BOOL CSampleDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CSampleDlg::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 CSampleDlg::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 CSampleDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSampleDlg::OnOK()
{
for(int i=0;i<512;i++){par[i]=0;}
jishu1=0;jishu2=0;jishu3=0;
husb=OpenUA300(); // 打開設備,得到句柄
ssinit(husb);
mtimer=SetTimer(1,1000,NULL); //設置計時器
wtimerres_2s=twosecond; //設置多媒體時鐘
TIMECAPS tc;
if(timeGetDevCaps(&tc,sizeof(TIMECAPS))==TIMERR_NOERROR)
{
wacc=min(max(tc.wPeriodMin,timeracc),tc.wPeriodMax);
timeBeginPeriod(wacc);
timerid=timeSetEvent(wtimerres_2s,wacc,(LPTIMECALLBACK)OneMilliSecondProc,(DWORD)this,TIME_PERIODIC);
}
}
void CSampleDlg::OnCancel()
{
// TODO: Add extra cleanup here
timeKillEvent(timerid); //卸載多媒體時鐘
timeEndPeriod(wacc);
KillTimer(mtimer); //卸載計時器
husb=CloseUA300(husb);
CDialog::OnCancel();
}
void CSampleDlg::drawpoly()
{
CDC *pDC;
pDC=GetDC();
CRect rect(20,20,546,220);
int leftmidx=20,leftmidy=120;
int rightmidx=546,rightmidy=120;
pDC->SelectStockObject(BLACK_BRUSH);
pDC->Rectangle(rect);
POINT point2[2]={{leftmidx,leftmidy},{rightmidx,rightmidy}};
//POINT datapoint[1024];
POINT datapoint[512];
CPen nextpen;
nextpen.CreatePen(PS_SOLID,2,RGB(255,0,0));
CPen* OldPen=pDC->SelectObject(&nextpen);
pDC->Polyline(point2,2);
//for(int i=0;i<=1024;i++){
for(int i=0;i<512;i++){
datapoint[i].y=(long)((120+(par[i]/(float)5)*(float)100));
datapoint[i].x=(long)(20+i);
//datapoint[i].x=(long)(20+i*0.5);
}
CPen pen;
pen.CreatePen(PS_SOLID,0,RGB(0,255,0));
CPen* pOldPen=pDC->SelectObject(&pen);
pDC->Polyline(datapoint,512);
CString str;
str.Format("%5d",jishu3);
pDC->TextOut(400,30,str);
ReleaseDC(pDC);
}
void CSampleDlg::OnTimer(UINT nIDEvent)
{
jishu3=jishu2-jishu1;
jishu2=0;
CSampleDlg::drawpoly();
}
void PASCAL OneMilliSecondProc(UINT wTimerID,
UINT msg,
DWORD dwUser,
DWORD dwl,
DWORD dw2)
{
jishu2++;
for(int i=0;i<511;i++)
{
par[i]=par[i+1];
}
par[511]=((ssad(husb,0,0)-2048)*0.002442);
//////////////////////////////////////////////////////////////
/*ssinit(husb);
coun=0; // 單點采集初始化
for(int i=0;i<1024;i++)
{
par[coun]=((ssad(husb,0,0)-2048)*0.002442);
coun++;
}*/
////////////////////////////////////////////////////
/*short int addat[1024];
minit(husb,0,1,0);
readdata(husb, addat,60,1024);
for(int i=0;i<1024;i++)
{
par[i]=(double)((addat[i]-2048)*0.002442);
}*/
/////////////////////////////////////////////////////
/*short int addat[64];
minit(husb,0,1,0);
readdata(husb, addat,60,64);
for(int i=0;i<64;i++){
for(int j=0;j<1022;j++){
par[j]=par[j+1];
}
}
int coun;
coun=960;
for(i=0;i<64;i++)
{
par[coun]=(double)((addat[i]-2048)*0.002442);
coun++;
}*/
/////////////////////////////////////////////////////
/*short int addat[1024];
minit2(husb,0,1,50,0); // 多點采集初始化,0-7通道, 1KHz,倍數1
readdata2(husb, addat,1024); // 多點采集, 256點
for(int i=0;i<1024;i++){
par[i]=(double)((addat[i]-2048)*0.002442);
}*/
/////////////////////////////////////////////////
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -