📄 usbhostsampledlg.cpp
字号:
// USBHOSTSAMPLEDlg.cpp : implementation file
//
#include "stdafx.h"
#include "USBHOSTSAMPLE.h"
#include "USBHOSTSAMPLEDlg.h"
#include "process.h"
#include "usb100.h"
#include "winioctl.h"
#include "usbdriver.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_DRAWPICTURE WM_USER+1
HWND hWindow;
unsigned int ADDataBuffer[8][1024];
bool g_KeepGoing = false;
bool g_Transfering = false;
void __cdecl ReceiveThreadFunction(HANDLE hDevice);
float SamFreq[7]={15.625,31.25,62.5,125,250,500,1000};
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CUSBHOSTSAMPLEDlg dialog
CUSBHOSTSAMPLEDlg::CUSBHOSTSAMPLEDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUSBHOSTSAMPLEDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUSBHOSTSAMPLEDlg)
// 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);
}
CUSBHOSTSAMPLEDlg::~CUSBHOSTSAMPLEDlg()
{
BackLinePen.DeleteObject();
CurvePen.DeleteObject();
LabelFont.DeleteObject();
TitleFont.DeleteObject();
}
void CUSBHOSTSAMPLEDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUSBHOSTSAMPLEDlg)
DDX_Control(pDX, IDC_COMBO_LastChannel, m_LastChannel);
DDX_Control(pDX, IDC_COMBO_FirstChannel, m_FirstChannel);
DDX_Control(pDX, IDC_EDIT_FREQ, m_Edit_Freq);
DDX_Control(pDX, IDC_SLIDERFREQ, m_SliderFreq);
DDX_Control(pDX, IDC_USB_LIST, m_UsbList);
DDX_Control(pDX, IDC_PICTURE_WAVE, m_Pictrue);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUSBHOSTSAMPLEDlg, CDialog)
//{{AFX_MSG_MAP(CUSBHOSTSAMPLEDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_START_BUTTON, OnStartButton)
ON_BN_CLICKED(IDC_CONFIG_BUTTON, OnConfigButton)
ON_BN_CLICKED(IDC_DEVICE_BUTTON, OnDeviceButton)
ON_BN_CLICKED(IDC_STOP_BUTTON, OnStopButton)
ON_BN_CLICKED(IDC_EXIT_BUTTON, OnExitButton)
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDERFREQ, OnCustomdrawSliderfreq)
ON_MESSAGE(WM_DRAWPICTURE,OnDrawPicture)
ON_BN_CLICKED(IDC_ABOUT_BUTTON, OnAboutButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUSBHOSTSAMPLEDlg message handlers
BOOL CUSBHOSTSAMPLEDlg::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
hWindow=*this;
strcpy(DeviceName,"Ezusb-0");
m_SliderFreq.SetRange(0,7);
m_SliderFreq.SetPos(4);
m_FirstChannel.SetCurSel(0);
m_LastChannel.SetCurSel(7);
CheckRadioButton(IDC_TRIG0_RADIO,IDC_TRIG1_RADIO,IDC_TRIG0_RADIO);
CheckRadioButton(IDC_VOLT0_RADIO,IDC_VOLT1_RADIO,IDC_VOLT0_RADIO);
BackLinePen.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(128, 128, 128));
CurvePen.CreatePen(PS_SOLID,1,RGB(255,255,0));
LabelFont.CreateFont(14,0,0,0,50,FALSE,0,0,0,0,0,0,0,"Arial");
TitleFont.CreateFont(20,0,0,0,50,FALSE,0,0,0,0,0,0,0,"Arial");
m_xStart=0;
m_yStart=-50;
m_LeftRim=50;
m_RightRim=40;
m_UpRim=40;
m_DownRim=40;
for(int j=0;j<8;j++)
{
for(int i=0;i<1024;i++)
{
m_PointList[j][i].x = i;
m_PointList[j][i].y = 2048;
ADDataBuffer[j][i] = 2048;
}
}
PostMessage(WM_DRAWPICTURE,0,0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CUSBHOSTSAMPLEDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else if (nID == SC_CLOSE)
{
if(g_KeepGoing)
{
MessageBox("请首先结束当前线程!", "错误", MB_ICONERROR | MB_OK);
return;
}
OnOK();
}
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 CUSBHOSTSAMPLEDlg::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 CUSBHOSTSAMPLEDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CUSBHOSTSAMPLEDlg::OnDrawPicture(WPARAM wParam,LPARAM lParam)
{
for(int j=0;j<8;j++)
{
for(int i=0;i<1024;i++)
m_PointList[j][i].y=ADDataBuffer[j][i];
}
CDC* pDC=m_Pictrue.GetDC();
CBrush brush;
brush.CreateSolidBrush(RGB(0,0,0));
GetUDLRrect();
pDC->FillRect(InnerRect,&brush);
DrawUDLRrect(pDC);
GetRectBlc(0,-50,1024,4150);
DrawBackLines(pDC);
DrawCurve(pDC);
DrawLab(pDC);
ReleaseDC(pDC);
}
///////////////////////////////////////////////////////////////////
//
// 以下是画图的相关函数。
//
///////////////////////////////////////////////////////////////////
void CUSBHOSTSAMPLEDlg::GetUDLRrect()
{
CRect rect;
m_Pictrue.GetClientRect(&rect);
m_InnerUHScreen = m_UpRim;
m_InnerDHScreen = rect.bottom - m_DownRim;
m_InnerLWScreen = m_LeftRim;
m_InnerRWScreen = rect.right - m_RightRim;
Urect.top=0;
Urect.bottom=m_InnerUHScreen;
Urect.left=0;
Urect.right=rect.right;
Drect.top=m_InnerDHScreen;
Drect.bottom=rect.bottom;
Drect.left=0;
Drect.right=rect.right;
Lrect.top=m_InnerUHScreen;
Lrect.bottom=m_InnerDHScreen;
Lrect.left=0;
Lrect.right=m_InnerLWScreen;
Rrect.top=m_InnerUHScreen;
Rrect.bottom=m_InnerDHScreen;
Rrect.left=m_InnerRWScreen;
Rrect.right=rect.right;
InnerRect.top=m_InnerUHScreen;
InnerRect.bottom=m_InnerDHScreen;
InnerRect.left=m_InnerLWScreen;
InnerRect.right=m_InnerRWScreen;
TotalRect.top=0;
TotalRect.bottom=rect.bottom;
TotalRect.left=0;
TotalRect.right=rect.right;
}
void CUSBHOSTSAMPLEDlg::GetRectBlc(float xRectStart,float yRectStart,float xRectEnd,float yRectEnd)
{
float m1,m2;
float x1,y1,x2,y2;
x1=min(xRectStart,xRectEnd);
x2=max(xRectStart,xRectEnd);
y1=min(yRectStart,yRectEnd);
y2=max(yRectStart,yRectEnd);
float lx,ly;
lx=x2-x1;
if(lx<0) return;
ly=y2-y1;
if(ly<0) return;
m1=lx/(m_InnerRWScreen-m_InnerLWScreen);
m2=ly/((m_InnerDHScreen-m_InnerUHScreen)/8);
m_XOriginScale =m1;
m_YOriginScale =m2;
}
void CUSBHOSTSAMPLEDlg::DrawUDLRrect (CDC *pDC)
{
pDC->SetBkColor(12632256);
pDC->SetBkMode(OPAQUE);
CBrush brush(pDC->GetBkColor ());
pDC->FillRect(Urect,&brush);
pDC->FillRect(Drect,&brush);
pDC->FillRect(Lrect,&brush);
pDC->FillRect(Rrect,&brush);
pDC->DrawEdge(TotalRect,EDGE_SUNKEN,BF_RECT);
}
void CUSBHOSTSAMPLEDlg::DrawBackLines (CDC *pDC)
{
float xL;
float xd;
float xLine;
xL=(float)(m_InnerRWScreen-m_InnerLWScreen);
if(xL<0) xL=-xL;
if(xL==0) return;
xd=xL/8;
m_xLineStart[0]=(float)m_InnerLWScreen;
m_xn=0;
xLine=xd;
while(xLine<xL)
{
m_xn=m_xn+1;
m_xLineStart[m_xn]=m_xn*xd+m_InnerLWScreen;
xLine=xLine+xd;
}
m_xn=m_xn+1;
m_xLineStart[m_xn]=(float)m_InnerRWScreen;
float yL;
float yd;
float yLine;
yL=(float)(m_InnerDHScreen-m_InnerUHScreen);
if(yL<0) yL=-yL;
if(yL==0) return;
yd=yL/8;
m_yLineStart[0]=(float)m_InnerDHScreen;
m_yn=0;
yLine=yd;
while(yLine<yL)
{
m_yn=m_yn+1;
m_yLineStart[m_yn]=m_InnerDHScreen-m_yn*yd;
yLine=yLine+yd;
}
m_yn=m_yn+1;
m_yLineStart[m_yn]=(float)m_InnerUHScreen;
CPen* pOldPen = pDC->SelectObject(&BackLinePen);
int i;
for(i=0;i<m_xn+1;i++)
{
pDC->MoveTo ((int)m_xLineStart[i],m_InnerUHScreen);
pDC->LineTo ((int)m_xLineStart[i],m_InnerDHScreen);
}
for(i=0;i<m_yn+1;i++)
{
pDC->MoveTo (m_InnerLWScreen,(int)m_yLineStart[i]);
pDC->LineTo (m_InnerRWScreen,(int)m_yLineStart[i]);
}
pDC->SelectObject (pOldPen);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -