📄 mytestdlg.cpp
字号:
// MyTestDlg.cpp : implementation file
//
#include "StdAfx.h"
#include "MyTest.h"
#include "MyTestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int sint;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CMyTestDlg dialog
CMyTestDlg::CMyTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyTestDlg)
// 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_ICON);
}
void CMyTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyTestDlg)
DDX_Control(pDX, IDC_LIST1, m_List);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyTestDlg, CDialog)
//{{AFX_MSG_MAP(CMyTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnUSBDLLInit)
ON_BN_CLICKED(IDC_BUTTON2, OnUSBInport)
ON_BN_CLICKED(IDC_BUTTON4, OnUSBDLLDone)
ON_BN_CLICKED(IDC_BUTTON5, OnClose)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON6, OnClearListText)
ON_BN_CLICKED(IDC_BUTTON7, OnLoadDraw)
ON_BN_CLICKED(IDC_BUTTON8, OnLoadPic)
ON_BN_CLICKED(IDC_BUTTON9, On_USB_SetControl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyTestDlg message handlers
BOOL CMyTestDlg::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 big icon
//SetIcon(IDR_ICON, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyTestDlg::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 CMyTestDlg::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();
}
}
HCURSOR CMyTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyTestDlg::OnUSBDLLInit()
{
//HANDLE InfoOutPipe,InfoInPipe,MainInPipe;
int sint;
char aa[10];
char mstr[20];
HANDLE ParentInstance=NULL; //声明句柄变量并赋空值
sint=USBDLLInit(ParentInstance); //发送初始化USB命令(必须)
strcpy(mstr,"USBDLLInit状态= ");
strcat(mstr,_itoa(sint,aa,10));
m_List.AddString(mstr); //将返回的状态显示在列表内
//****************************************************
//sint包含了调用命令后的返回值(=0表示成功;非0则失败)
//****************************************************
}
void CMyTestDlg::OnUSBInport()
{
//----------------------------------------------------
//读某地址处的数据
//函数:
//USB_Inport(HANDLE instance, char Addr, char *Data)
//----------------------------------------------------
int sint;
char aa[10];
char mstr[20];
char iadd=1;
char data[10];
int ih[2];
HANDLE ParentInstance=NULL;
sint=USB_Inport(ParentInstance,iadd,data);
strcpy(mstr,"USBD_Inport状态= ");
ih[0]=data[0] & 0x00ff;
strcat(mstr,itoa(ih[0],aa,10));
m_List.AddString(mstr);
}
void CMyTestDlg::OnUSBDLLDone()
{
//------------------------------------
//系统或应用程序结束时一定要将设备关闭
//USBDLLDone()是关闭设备的函数 (无参数)
//------------------------------------
int sint;
char aa[10];
char mstr[20];
sint=USBDLLDone();
strcpy(mstr,"USBDDLLDone状态= ");
strcat(mstr,_itoa(sint,aa,10));
m_List.AddString(mstr);
}
void CMyTestDlg::OnClose()
{
//---------------------------
//系统退出时一定要关闭设备
//---------------------------
OnUSBDLLDone();
OnOK();
}
void CMyTestDlg::OnButton3()
{
//----------------------------------------------------
//向某一地址处写数据函数
// USB_Outport(HANDLE instance, char Addr, char Data)
//----------------------------------------------------
char aa[10];
char mstr[20];
char iadd=0,data=0;
HANDLE ParentInstance=NULL;
sint=USB_Outport(ParentInstance,iadd,data);
strcpy(mstr,"USBD_Outport状态= ");
strcat(mstr,_itoa(sint,aa,10));
m_List.AddString(mstr);
}
void CMyTestDlg::OnClearListText()
{
//清空列表框
m_List.ResetContent();
}
void CMyTestDlg::OnLoadDraw()
{
MyDrawPoint.DoModal();
}
void CMyTestDlg::OnLoadPic()
{
// TODO: Add your control notification handler code here
MyPicNew.DoModal();
}
void CMyTestDlg::On_USB_SetControl()
{
// TODO: Add your control notification handler code here
char aa[10];
char mstr[200];
char data=0;
HANDLE ParentInstance=NULL;
sint=USB_SetControl(ParentInstance,data);
strcpy(mstr,"USB_SetControl状态= ");
strcat(mstr,_itoa(sint,aa,10));
m_List.AddString(mstr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -