📄 usbhostwavedlg.cpp
字号:
// USBHOSTWAVEDlg.cpp : implementation file
//
#include "stdafx.h"
#include "USBHOSTWAVE.h"
#include "USBHOSTWAVEDlg.h"
#include "math.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 PI 3.1415926
#define WM_DRAWPICTURE WM_USER+1
bool g_KeepGoing = false;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CUSBHOSTWAVEDlg dialog
CUSBHOSTWAVEDlg::CUSBHOSTWAVEDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUSBHOSTWAVEDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUSBHOSTWAVEDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CUSBHOSTWAVEDlg::~CUSBHOSTWAVEDlg()
{
BackLinePen.DeleteObject();
CurvePen.DeleteObject();
LabelFont.DeleteObject();
TitleFont.DeleteObject();
}
void CUSBHOSTWAVEDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUSBHOSTWAVEDlg)
DDX_Control(pDX, IDC_USB_LIST, m_UsbList);
DDX_Control(pDX, IDC_SLIDERFREQ, m_SliderFreq);
DDX_Control(pDX, IDC_SLIDERAMP, m_SliderAmp);
DDX_Control(pDX, IDC_EDIT_FREQ, m_Edit_Freq);
DDX_Control(pDX, IDC_EDIT_AMP, m_Edit_Amp);
DDX_Control(pDX, IDC_PICTURE_WAVE, m_Pictrue);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUSBHOSTWAVEDlg, CDialog)
//{{AFX_MSG_MAP(CUSBHOSTWAVEDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_PHACKLE_BUTTON, OnPhackleButton)
ON_BN_CLICKED(IDC_NHACKLE_BUTTON, OnNhackleButton)
ON_BN_CLICKED(IDC_TRIANGLE_BUTTON, OnTriangleButton)
ON_BN_CLICKED(IDC_SQUARE_BUTTON, OnSquareButton)
ON_BN_CLICKED(IDC_SIN_BUTTON, OnSinButton)
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDERFREQ, OnCustomdrawSliderfreq)
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDERAMP, OnCustomdrawSlideramp)
ON_BN_CLICKED(IDC_DEVICE_BUTTON, OnDeviceButton)
ON_BN_CLICKED(IDC_CONFIG_BUTTON, OnConfigButton)
ON_BN_CLICKED(IDC_INTERFACE_BUTTON, OnInterfaceButton)
ON_BN_CLICKED(IDC_ENDPOINT_BUTTON, OnEndpointButton)
ON_BN_CLICKED(IDC_STRING_BUTTON, OnStringButton)
ON_BN_CLICKED(IDC_FRAME_BUTTON, OnFrameButton)
ON_BN_CLICKED(IDC_BUTTON_FREQ, OnButtonFreq)
ON_BN_CLICKED(IDC_BUTTON_AMP, OnButtonAmp)
ON_BN_CLICKED(IDC_SEND_BUTTON, OnSendButton)
ON_BN_CLICKED(IDC_END_BUTTON, OnEndButton)
ON_BN_CLICKED(IDC_EXIT_BUTTON, OnExitButton)
ON_MESSAGE(WM_DRAWPICTURE,OnDrawPicture)
ON_BN_CLICKED(IDC_CLEAR_BUTTON, OnClearButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUSBHOSTWAVEDlg message handlers
BOOL CUSBHOSTWAVEDlg::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
strcpy(DeviceName,"Ezusb-0");
m_SliderFreq.SetRange(1,31999);
m_SliderFreq.SetPos(31999);
m_SliderAmp.SetRange(0,250);
m_SliderAmp.SetPos(250);
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=-64;
m_LeftRim=50;
m_RightRim=40;
m_UpRim=40;
m_DownRim=40;
GetUDLRrect();
GetRectBlc(0,-64,1024,320);
OnPhackleButton();
return TRUE; // return TRUE unless you set the focus to a control
}
void CUSBHOSTWAVEDlg::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 CUSBHOSTWAVEDlg::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 CUSBHOSTWAVEDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CUSBHOSTWAVEDlg::OnDrawPicture(WPARAM wParam,LPARAM lParam)
{
CDC* pDC=m_Pictrue.GetDC();
CBrush brush;
brush.CreateSolidBrush(RGB(0,0,0));
pDC->FillRect(InnerRect,&brush);
DrawUDLRrect(pDC);
DrawBackLines(pDC);
DrawCurve(pDC);
DrawLab(pDC);
ReleaseDC(pDC);
}
///////////////////////////////////////////////////////////////////
//
// 以下是画图的相关函数。
//
///////////////////////////////////////////////////////////////////
void CUSBHOSTWAVEDlg::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 CUSBHOSTWAVEDlg::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);
m_XOriginScale =m1;
m_YOriginScale =m2;
}
void CUSBHOSTWAVEDlg::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 CUSBHOSTWAVEDlg::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/6;
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);
}
void CUSBHOSTWAVEDlg::DrawLab(CDC *pDC)
{
pDC->SetBkMode (OPAQUE);
CFont* pOldFont=(CFont*)pDC->SelectObject(&LabelFont);
pDC->TextOut(m_InnerLWScreen-30,m_InnerUHScreen-27,"幅度值");
pDC->TextOut(m_InnerLWScreen/2-15 + m_InnerRWScreen/2,m_InnerDHScreen+ 20, "点数值");
char str[10];
for(int i=0;i<m_yn+1;i++)
{
sprintf(str,"%d",(-64)+i*64);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -