📄 pci7505dlg.cpp
字号:
// pci7505Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "pci7505.h"
#include "pci7505Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
HINSTANCE pci7505dll=NULL;
typedef int(*pci7505check)(DWORD dwVendorID, DWORD dwDeviceID, BOOL fUseInt,DWORD cardNO);
typedef int(*pci7505di)(long hPlx, BOOL fLocalAddr,int ch);
typedef void(*pci7505do)(long hPlx, BOOL fLocalAddr,int ch,int dodata);
typedef int(*pci7505close)(long hPlx);
pci7505check check;
pci7505di di;
pci7505do dio;
pci7505close close;
int hplx;
/////////////////////////////////////////////////////////////////////////////
// CPci7505Dlg dialog
#define WM_SYSTRAYICONMSG WM_USER+300
#define SYSTRAYID 100
CPci7505Dlg::CPci7505Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CPci7505Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPci7505Dlg)
m_fs = -1;
m_dio1 = 0;
m_dio2 = 0;
m_nCount = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bHasTray = false;
m_bStart = TRUE;
k=0;
}
void CPci7505Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPci7505Dlg)
DDX_Radio(pDX, IDC_RADIO1, m_fs);
DDX_Text(pDX, IDC_EDIT1, m_dio1);
DDX_Text(pDX, IDC_EDIT2, m_dio2);
DDX_Text(pDX, IDC_EDIT3, m_nCount);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPci7505Dlg, CDialog)
//{{AFX_MSG_MAP(CPci7505Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_exitBUTTON, OnexitBUTTON)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_doBUTTON, OndoBUTTON)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_HIDE, OnHide)
ON_COMMAND(IDC_SHOW, OnShow)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPci7505Dlg message handlers
BOOL CPci7505Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
if(pci7505dll!=NULL)
{
MessageBox("The pci7505vc.dll alread been loaded.");
return TRUE;
}
pci7505dll=LoadLibrary("pci7505vc.dll");
if(pci7505dll==NULL)
{
char msg[30];
strcpy(msg,"Cannot load the pci7505.DLL DLL.");
strcat(msg,"Make sure that the file pci7505vc.DLL");
strcat(msg,"is in your \\WINDOWS\\SYSTEM directory.");
MessageBox(msg);
}
check=(pci7505check)GetProcAddress(pci7505dll,"pci7505check");
di=(pci7505di)GetProcAddress(pci7505dll,"pci7505di");
dio=(pci7505do)GetProcAddress(pci7505dll,"pci7505do");
close=(pci7505close)GetProcAddress(pci7505dll,"pci7505close");
UpdateData(FALSE);
hplx=0;
hplx=check(0, 0, FALSE,1);
m_fs=0;
UpdateData(false);
int i;
jc=1;
for(i=0;i<2;i++)
{
// diod[i]=0;
// olddid[i]=0;
}
GetDlgItem(IDC_doBUTTON)->EnableWindow(FALSE);
i=SetTimer(1,30,NULL);
if(i==0)
AfxMessageBox("cannot install timer!");
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CPci7505Dlg::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 CPci7505Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPci7505Dlg::OnTimer(UINT nIDEvent)
{
/*
int s1,s2;
if(m_fs==0)
{
s1=di(hplx, false,0);
s2=di(hplx, false,1);
m_dio1=s1;
m_dio2=s2;
UpdateData(false);
}
CDialog::OnTimer(nIDEvent); */
}
void CPci7505Dlg::OnexitBUTTON()
{
OnOK();
}
void CPci7505Dlg::OnRadio1()
{
m_fs=0;
UpdateData(TRUE);
}
void CPci7505Dlg::OndoBUTTON()
{
int s1,s2;
if(m_fs==1)
{
UpdateData(true);
s1=m_dio1;
s2=m_dio2;
dio(hplx, false,0,s1);
dio(hplx, false,1,s2);
}
// TODO: Add your control notification handler code here
}
void CPci7505Dlg::OnRadio2()
{
KillTimer(1);
m_fs=1;
UpdateData(TRUE);
int ir;
ir=MessageBox(
"你确定设置为输出方式吗?",
"pci7505开关量测试界面",
MB_YESNO + MB_ICONQUESTION);
if (ir==IDNO)
{
int i=SetTimer(1,30,NULL);
if(i==0)
AfxMessageBox("cannot install timer!");
UpdateData(FALSE);
GetDlgItem(IDC_doBUTTON)->EnableWindow(FALSE);
}
else
{
m_fs=1;
GetDlgItem(IDC_doBUTTON)->EnableWindow(TRUE);
}
}
void CPci7505Dlg::OnButton1()
{
BOOL bRun=true;
for (;bRun;)
{
for(;;)
{
int s1=di(hplx, false,0);
int s2=di(hplx,false,1);
if (s2!=0)
{
k++;
m_nCount=k;
break;
}
}
UpdateData(FALSE);
UpdateWindow();
/*
if ( ::PeekMessage(&msg, NULL, NULL, NULL,NULL) )
{
if( msg.message == WM_KEYDOWN )
{
//::TranslateMessage(&msg);
if( msg.wParam == 'c' )//大写字母加单引号表示按下哪个字母键
{
run = false;//退出循环
break;
}
}
}*/
if(k==5)
break;
}
// close(hplx);
return;
}
void CPci7505Dlg::OnHide()
{
ShowWindow( SW_HIDE );
if( !m_bHasTray )
{
m_sysTrayIcon.SetDefaultMenu( IDR_TRAYMENU );
m_sysTrayIcon.SetMenuWnd( GetSafeHwnd() );
m_sysTrayIcon.CreateTray( NULL,WM_SYSTRAYICONMSG, m_bmpLogos.ExtractIcon( 0 ), SYSTRAYID,"自动关机:正在计时..." );
m_sysTrayIcon.CreateIconList( &m_bmpLogos );
m_bHasTray = true;
}
m_sysTrayIcon.AddIcon();
m_sysTrayIcon.PlayAnimation();
//
if ( !m_bStart )
{
OnButton1();
}
}
void CPci7505Dlg::OnShow()
{
ShowWindow( SW_SHOW );
m_sysTrayIcon.StopAnimation();
m_sysTrayIcon.RemoveIcon();
}
void CPci7505Dlg::OnButton2()
{
// dio(hplx,false,0,0);
dio(hplx,false,1,32);
AfxMessageBox("ok");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -