?? 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; // 讀入的數(shù)據(jù)長度
/////////////////////////////////////////////////////////////////////////////
// CSysApp initialization
BOOL CSysApp::InitInstance()
{
m_CurrentDeviceNum=0; // 指定當(dāng)前設(shè)備的ID標(biāo)示符
/*
/////
// 創(chuàng)建互斥對象
::CreateMutex(NULL, NULL, m_pszExeName); // m_pszExeName為本程序的執(zhí)行名
if(GetLastError()==ERROR_ALREADY_EXISTS) // 第二次創(chuàng)建應(yīng)用程序
{
// 為更安全的進(jìn)行窗口搜索,我們搜索桌面的子窗口來進(jìn)行的
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);
// 使窗口獲得焦點(diǎn)
pPrevWnd->SetForegroundWindow();
// 如果該窗口有彈出窗口,則首先將彈出窗口調(diào)用前臺
pPrevWnd->GetLastActivePopup()->SetForegroundWindow();
// 退出當(dāng)前實(shí)例:
return FALSE;
}
// 沒有找到,繼續(xù)搜索
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或以上的顯示器分辨率,繼續(xù)嗎?",MB_ICONWARNING|MB_YESNO,0)==IDNO)
{
ExitInstance();
return FALSE;
}
}
///////////////////////////////////////////////
// 應(yīng)用程序正常創(chuàng)建代碼:
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
// 讓W(xué)INDOWS登記該程序的缺省數(shù)據(jù)文件名擴(kuò)展名
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); // 打開第一個(gè)USB設(shè)備
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); // 打開第一個(gè)USB設(shè)備
}
void CSysApp::OnUpdateOpenDevice(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CSysApp::OpenDevice(int DeviceNum)
{
BeginWaitCursor(); // 開始漏斗鼠標(biāo)
CDocument* pDoc;
pDoc=pADDocTemplate->CreateNewDocument(); // 創(chuàng)建新文檔
pADDoc=(CADDoc*)pDoc; // 保存文檔對象
// 創(chuàng)建該文檔對象的子幀窗口
m_ADFrame=(CADFrame*)pADDocTemplate->CreateNewFrame(pDoc, NULL);
// 設(shè)置默認(rèn)的文檔標(biāo)題
//pADDocTemplate->SetDefaultTitle(pDoc);
// 創(chuàng)建文檔實(shí)例
//pDoc->OnNewDocument();
// 初始化FRAME子幀窗口,且觸發(fā)FRAME的OnUpdate函數(shù)
pADDocTemplate->InitialUpdateFrame(m_ADFrame, pDoc);
// CString str;
// str.Format("-%d", DeviceNum);
// str=DeviceName+str;
// str=str+"] - [阿爾泰設(shè)備測試系統(tǒng)";
// pDoc->SetTitle(str);
EndWaitCursor(); // 停止漏斗鼠標(biāo)
}
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:當(dāng)文件不存在時(shí),是否要求新建
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("對不起,該文件不能解析數(shù)據(jù)文件, 是否繼續(xù)",MB_YESNO, 0)==IDNO)
return;
bFile = FALSE;
}
CHistDataDoc* pDoc;
BeginWaitCursor(); // 開始漏斗鼠標(biāo)
pDoc=(CHistDataDoc*)pHistDataTemplate->OpenDocumentFile(strNewFileName); // 先傳遞文件名到pDoc的消息函數(shù)OnOpenDocument
strNewFileName="歷史數(shù)據(jù): "+ strNewFileName;
pDoc->SetTitle(strNewFileName); // 置文檔新標(biāo)題
EndWaitCursor(); // 停止漏斗鼠標(biāo)
}
void CSysApp::OnOpenDIO()
{
// TODO: Add your command handler code here
CDIODoc* pDoc;
BeginWaitCursor();
pDoc=(CDIODoc*)pDIOTemplate->OpenDocumentFile(NULL);
pDoc->SetTitle("開關(guān)量測試程序");
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("對不起,該文件不能解析數(shù)據(jù)文件, 是否繼續(xù)",MB_YESNO, 0)==IDNO)
return NULL;
bFile = FALSE;
}
CHistDataDoc* pDoc;
BeginWaitCursor(); // 開始漏斗鼠標(biāo)
pDoc=(CHistDataDoc*)pHistDataTemplate->OpenDocumentFile(lpszFileName); // 先傳遞文件名到pDoc的消息函數(shù)OnOpenDocument
str = lpszFileName;
str="歷史數(shù)據(jù):"+ str;
pDoc->SetTitle(str); // 置文檔新標(biāo)題
EndWaitCursor(); // 停止漏斗鼠標(biāo)
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("計(jì)數(shù)器測試");
// EndWaitCursor();
}
void CSysApp::OnUpdateOpenConter(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -