📄 sys.cpp
字号:
// Sys.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Sys.h"
#include "MainFrm.h"
#include "ADFrm.h"
#include "ADDoc.h"
#include "ADDigitView.h"
#include "ADWaveView.h"
#include "ADSaveView.h"
#include "DIOFrm.h"
#include "DIODoc.h"
#include "DIOView.h"
#include "HistDataFrm.h"
#include "HistDataDoc.h"
#include "HistDigitView.h"
BOOL bFile=TRUE;
#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_OpenDevice, OnOpenDevice)
ON_UPDATE_COMMAND_UI(IDM_OpenDevice, OnUpdateOpenDevice)
ON_COMMAND(IDM_ProcessHistData, OnProcessHistData)
ON_COMMAND(IDM_OpenDIO, OnOpenDIO)
ON_UPDATE_COMMAND_UI(IDM_OpenDIO, OnUpdateOpenDIO)
ON_COMMAND(IDM_OpenDA, OnOpenDA)
ON_UPDATE_COMMAND_UI(IDM_OpenDA, OnUpdateOpenDA)
//}}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()
{
m_CurrentDeviceNum=0; // 指定当前设备的ID标示符
/*
/////
// 创建互斥对象
::CreateMutex(NULL, NULL, m_pszExeName); // m_pszExeName为本程序的执行名
if(GetLastError()==ERROR_ALREADY_EXISTS) // 第二次创建应用程序
{
// 为更安全的进行窗口搜索,我们搜索桌面的子窗口来进行的
CWnd* pPrevWnd=CWnd::GetDesktopWindow()->GetWindow(GW_HWNDFIRST);//GW_CHILD);
//pPrevWnd->ShowWindow(SW_SHOWMINIMIZED);
while(pPrevWnd)
{
// 获取该窗口属性
if(::GetProp(pPrevWnd->GetSafeHwnd(),m_pszExeName))
{
// 查找该窗口,如果它已最小化,则将它还原
if(pPrevWnd->IsIconic())
pPrevWnd->ShowWindow(SW_RESTORE);
// 使窗口获得焦点
pPrevWnd->SetForegroundWindow();
// 如果该窗口有弹出窗口,则首先将弹出窗口调用前台
pPrevWnd->GetLastActivePopup()->SetForegroundWindow();
// 退出当前实例:
return FALSE;
}
// 没有找到,继续搜索
pPrevWnd=pPrevWnd->GetWindow(GW_HWNDNEXT);
//pPrevWnd->CloseWindow();//ShowWindow(SW_SHOWMINIMIZED);
}
TRACE("Cound not Find previous instance main window\n");
return FALSE;
}
*/
///////////////////////////////////////////////
// 判断用户的显示器模式是否为1024*768
int Len=GetSystemMetrics(SM_CXSCREEN); // 取得屏幕宽度
if(Len<1024) // 如果屏幕宽度大小1024,则
{
if(AfxMessageBox("请最好使用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.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// 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.
pADDocTemplate = new CMultiDocTemplate(
IDR_AD,
RUNTIME_CLASS(CADDoc),
RUNTIME_CLASS(CADFrame), // custom MDI child frame
RUNTIME_CLASS(CADDigitView));
AddDocTemplate(pADDocTemplate);
pHistDataTemplate = new CMultiDocTemplate(
IDR_HistData,
RUNTIME_CLASS(CHistDataDoc),
RUNTIME_CLASS(CHistDataFrame), // custom MDI child frame
RUNTIME_CLASS(CHistDigitView));
AddDocTemplate(pHistDataTemplate);
pDIOTemplate = new CMultiDocTemplate(
IDR_IO,
RUNTIME_CLASS(CDIODoc),
RUNTIME_CLASS(CDIOFrm), // custom MDI child frame
RUNTIME_CLASS(CDIOView));
AddDocTemplate(pDIOTemplate);
// pCntlrTemplate = new CMultiDocTemplate(
// IDR_Counter,
// RUNTIME_CLASS(CCounterDoc),
// RUNTIME_CLASS(CCounterFrm), // custom MDI child frame CChildFrame
// RUNTIME_CLASS(CCounterView));
// AddDocTemplate(pCntlrTemplate);
// 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; char str[100];
sprintf(str, "USB2080-%d ", m_CurrentDeviceNum);
MainFrmName = pMainFrame->GetTitle();
MainFrmName = str+MainFrmName;
pMainFrame->SetTitle(MainFrmName);
OpenDevice(m_CurrentDeviceNum); // 打开第一个USB设备
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
void CSysApp::OnOpenDevice()
{
// TODO: Add your command handler code here
OpenDevice(0); // 打开第一个USB设备
}
void CSysApp::OnUpdateOpenDevice(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CSysApp::OpenDevice(int DeviceNum)
{
BeginWaitCursor(); // 开始漏斗鼠标
CDocument* pDoc;
pDoc=pADDocTemplate->CreateNewDocument(); // 创建新文档
pADDoc=(CADDoc*)pDoc; // 保存文档对象
// 创建该文档对象的子帧窗口
m_ADFrame=(CADFrame*)pADDocTemplate->CreateNewFrame(pDoc, NULL);
// 设置默认的文档标题
//pADDocTemplate->SetDefaultTitle(pDoc);
// 创建文档实例
//pDoc->OnNewDocument();
// 初始化FRAME子帧窗口,且触发FRAME的OnUpdate函数
pADDocTemplate->InitialUpdateFrame(m_ADFrame, pDoc);
// CString str;
// str.Format("-%d", DeviceNum);
// str=DeviceName+str;
// str=str+"] - [阿尔泰设备测试系统";
// pDoc->SetTitle(str);
EndWaitCursor(); // 停止漏斗鼠标
}
void CSysApp::OpenDigitListView(void)
{
}
void CSysApp::OnProcessHistData()
{
// TODO: Add your command handler code here
CString strNewFileName;
// 弹出文件对话框
if (!(DoPromptFileName(strNewFileName, IDS_ProccessHistData,
OFN_HIDEREADONLY , TRUE, NULL))) // OFN_CREATEPROMPT:当文件不存在时,是否要求新建
return;
CFile file;
CFileStatus status;
if (!file.GetStatus(strNewFileName, status))
{
strNewFileName=strNewFileName+" 不存在!";
AfxMessageBox(strNewFileName,MB_ICONSTOP, 0);
return; // 如果文件不存
}
CFile File;
FILE_HEADER m_Header;
File.Open(strNewFileName, USB2080_modeRead);
File.Seek(0,CFile::begin);
File.Read((WORD*)&m_Header,sizeof(m_Header)); // 文件信息由HistDigitView类将其置在HistDataFrame的对话框条上OnInitialUpdate
File.Close();
if(m_Header.DeviceNum != DEFAULT_DEVICE_NUM)
{
if(AfxMessageBox("对不起,该文件不能解析数据文件, 是否继续",MB_YESNO, 0)==IDNO)
return;
bFile = FALSE;
}
CHistDataDoc* pDoc;
BeginWaitCursor(); // 开始漏斗鼠标
pDoc=(CHistDataDoc*)pHistDataTemplate->OpenDocumentFile(strNewFileName); // 先传递文件名到pDoc的消息函数OnOpenDocument
strNewFileName="历史数据: "+ strNewFileName;
pDoc->SetTitle(strNewFileName); // 置文档新标题
EndWaitCursor(); // 停止漏斗鼠标
}
void CSysApp::OnOpenDIO()
{
// TODO: Add your command handler code here
CDIODoc* pDoc;
BeginWaitCursor();
pDoc=(CDIODoc*)pDIOTemplate->OpenDocumentFile(NULL);
pDoc->SetTitle("开关量测试程序");
EndWaitCursor();
}
void CSysApp::OnUpdateOpenDIO(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
int CSysApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
return CWinApp::ExitInstance();
}
void CSysApp::OnOpenDA()
{
// TODO: Add your command handler code here
}
void CSysApp::OnUpdateOpenDA(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
CDocument* CSysApp::OpenDocumentFile(LPCTSTR lpszFileName)
{
// TODO: Add your specialized code here and/or call the base class
CString str;
CFile file;
CFileStatus status;
if (!file.GetStatus(lpszFileName, status))
{
str=lpszFileName;
str=str+" 不存在!";
AfxMessageBox(lpszFileName,MB_ICONSTOP, 0);
return NULL; // 如果文件不存
}
CFile File;
FILE_HEADER m_Header;
File.Open(lpszFileName, USB2080_modeRead);
File.Seek(0,CFile::begin);
File.Read((WORD*)&m_Header,sizeof(m_Header)); // 文件信息由HistDigitView类将其置在HistDataFrame的对话框条上OnInitialUpdate
File.Close();
if(m_Header.DeviceNum != DEFAULT_DEVICE_NUM)
{
if(AfxMessageBox("对不起,该文件不能解析数据文件, 是否继续",MB_YESNO, 0)==IDNO)
return NULL;
bFile = FALSE;
}
CHistDataDoc* pDoc;
BeginWaitCursor(); // 开始漏斗鼠标
pDoc=(CHistDataDoc*)pHistDataTemplate->OpenDocumentFile(lpszFileName); // 先传递文件名到pDoc的消息函数OnOpenDocument
str = lpszFileName;
str="历史数据:"+ str;
pDoc->SetTitle(str); // 置文档新标题
EndWaitCursor(); // 停止漏斗鼠标
return pDoc;
//return CWinApp::OpenDocumentFile(lpszFileName);
}
void CSysApp::OnOpenConter()
{
// TODO: Add your command handler code here
// BeginWaitCursor();
// CDocument* pDoc;
// pDoc = pCntlrTemplate->CreateNewDocument ();
// m_pSysDoc = (CCounterDoc*)pDoc;
// m_pShowCh = (CCounterFrm*)pCntlrTemplate->CreateNewFrame(pDoc,NULL);
// pCntlrTemplate->InitialUpdateFrame (m_pShowCh,pDoc);
// pDoc->SetTitle("计数器测试");
// EndWaitCursor();
}
void CSysApp::OnUpdateOpenConter(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -