// GPIOBeepDlg.cpp : implementation file
//
#include "stdafx.h"
#include "GPIOBeep.h"
#include "GPIOBeepDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGPIOBeepDlg dialog
CGPIOBeepDlg::CGPIOBeepDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGPIOBeepDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGPIOBeepDlg)
// 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);
}
void CGPIOBeepDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGPIOBeepDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGPIOBeepDlg, CDialog)
//{{AFX_MSG_MAP(CGPIOBeepDlg)
ON_BN_CLICKED(IDC_OPEN_PIO1, OnOpenPio1)
ON_BN_CLICKED(IDC_CLOSE_PIO1, OnClosePio1)
ON_BN_CLICKED(IDC_BEEP_ON, OnBeepOn)
ON_BN_CLICKED(IDC_BEEP_OFF, OnBeepOff)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGPIOBeepDlg message handlers
BOOL CGPIOBeepDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
#include "gpio.h"
HANDLE hFile=INVALID_HANDLE_VALUE;
void CGPIOBeepDlg::OnOpenPio1()
{
BOOL ret;
BYTE pinnum=10;
hFile=CreateFile(TEXT("PIO:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,0);
if(hFile==INVALID_HANDLE_VALUE)
{
MessageBox(_T("打开GPIO驱动失败!"));
return;
}
else
MessageBox(_T("打开GPIO驱动成功!"));
ret=::DeviceIoControl(hFile,IOCTL_GPH_SET_PIN_OUT,&pinnum,1,NULL,0,NULL,NULL);
if(ret!=TRUE)
{
OnClosePio1();
MessageBox(_T("设置GPH10引脚输出失败!"));
return;
}
CButton*pOpenButton=(CButton*)GetDlgItem(IDC_OPEN_PIO1);
CButton*pCloseButton=(CButton*)GetDlgItem(IDC_CLOSE_PIO1);
pOpenButton->EnableWindow(FALSE);
pCloseButton->EnableWindow(TRUE);
}
void CGPIOBeepDlg::OnClosePio1()
{
// TODO: Add your control notification handler code here
if(hFile!=INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
hFile=INVALID_HANDLE_VALUE;
}
CButton*pOpenButton=(CButton*)GetDlgItem(IDC_OPEN_PIO1);
CButton*pCloseButton=(CButton*)GetDlgItem(IDC_CLOSE_PIO1);
pOpenButton->EnableWindow(TRUE);
pCloseButton->EnableWindow(FALSE);
}
void CGPIOBeepDlg::OnBeepOn()
{
// TODO: Add your control notification handler code here
BOOL ret;
BYTE pinnum=10;
ret=::DeviceIoControl(hFile,IOCTL_GPH_CLR_PIN,&pinnum,1,NULL,0,NULL,NULL);
if(ret!=TRUE)
MessageBox(_T("设置GPH10低电平失败!"));
}
void CGPIOBeepDlg::OnBeepOff()
{
// TODO: Add your control notification handler code here
BOOL ret;
BYTE pinnum=10;
ret=::DeviceIoControl(hFile,IOCTL_GPH_SET_PIN,&pinnum,1,NULL,0,NULL,NULL);
if(ret!=TRUE)
MessageBox(_T("设置GPH10高电平失败!"));
}
void CGPIOBeepDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
CDialog::OnDestroy();
OnClosePio1();
}
这是程序