SSPC-Tester/Driver/急停报警相关资料/PCI2312 Samples/VC/Advanced/Sys.cpp

247 lines
6.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Sys.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Sys.h"
#include "MainFrm.h"
#include "PCI2312.h"
#include "DIOFrm.h"
#include "DIODoc.h"
#include "DIOView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSysApp
BEGIN_MESSAGE_MAP(CSysApp, CWinApp)
//{{AFX_MSG_MAP(CSysApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(IDM_OpenDIO, OnOpenDIO)
ON_UPDATE_COMMAND_UI(IDM_OpenDIO, OnUpdateOpenDIO)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSysApp construction
CSysApp::CSysApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CSysApp object
CSysApp theApp;
LONG ReadSizeWords; // 读入的数据长度
/////////////////////////////////////////////////////////////////////////////
// CSysApp initialization
BOOL CSysApp::InitInstance()
{
TCHAR szMutex[256];
m_CurrentDeviceID = 0; // 指定当前设备的ID标示符
int DeviceID = 0;
while (TRUE)
{
swprintf_s(szMutex, _T("PCI2312-%d"), DeviceID);
// 创建互斥对象
m_hMutex=::CreateMutex(NULL, NULL, szMutex); // m_pszExeName为本程序的执行名
if (GetLastError() == ERROR_ALREADY_EXISTS) // 第二次创建应用程序
{
DeviceID++;
continue; // 如果已经创建,则继续下一个设备的应用程序创建
}
else
{
m_CurrentDeviceID = DeviceID;
m_hDevice = PCI2312_CreateDevice(m_CurrentDeviceID);
if (m_hDevice == INVALID_HANDLE_VALUE)
{
AfxMessageBox(L"对不起,您的所有设备已被相应程序管理,您不能再创建新实例...", MB_ICONWARNING, 0);
}
break;
}
}
//if(m_CurrentDeviceID<DeviceCount) AfxMessageBox("您可以再启动该应用程序实例来管理下一个设备");
///////////////////////////////////////////////
// 判断用户的显示器模式是否为1024*768
int Len = GetSystemMetrics(SM_CXSCREEN); // 取得屏幕宽度
if(Len<1024) // 如果屏幕宽度大小1024
{
if(AfxMessageBox(L"请最好使用1024*768或以上的显示器分辨率继续吗", MB_ICONWARNING | MB_YESNO, 0)==IDNO)
{
ExitInstance();
return FALSE;
}
}
// 应用程序正常创建代码:
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(16); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
pIOTemplate= new CMultiDocTemplate(
IDR_IO,
RUNTIME_CLASS(CDIODoc),
RUNTIME_CLASS(CDIOFrm), // custom MDI child frame
RUNTIME_CLASS(CDIOView));
AddDocTemplate(pIOTemplate);
// Enable DDE Execute open
// 让WINDOWS登记该程序的缺省数据文件名扩展名
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
//if (!ProcessShellCommand(cmdInfo))
// return FALSE;
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// The main window has been initialized, so show and update it.
// pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->ShowWindow(SW_SHOWMAXIMIZED); // 使主窗口最大化
pMainFrame->UpdateWindow();
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles(); // 支持拖放功能
::SetProp(m_pMainWnd->GetSafeHwnd(), m_pszExeName, (HANDLE)1);
CString MainFrmName;
WCHAR str[100];
swprintf_s(str, L"PCI2312-%d ", m_CurrentDeviceID);
MainFrmName = pMainFrame->GetTitle();
MainFrmName = str + MainFrmName;
pMainFrame->SetTitle(MainFrmName);
OnOpenDIO();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// 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)
// No message handlers
//}}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()
// App command to run the dialog
void CSysApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CSysApp message handlers
int CSysApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
ReleaseMutex(m_hMutex);
return CWinApp::ExitInstance();
}
void CSysApp::OnOpenDIO()
{
// TODO: Add your command handler code here
CDIODoc* pDoc;
BeginWaitCursor(); // 开始漏斗鼠标
pDoc=(CDIODoc*)pIOTemplate->OpenDocumentFile(NULL); // 先传递文件名到pDoc的消息函数OnOpenDocument
pDoc->SetTitle(L"开关量测试"); // 置文档新标题
EndWaitCursor(); // 停止漏斗鼠标
}
void CSysApp::OnUpdateOpenDIO(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}