⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trend.cpp

📁 此文件为VC++开发环境下的OPC client trend 源代码
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////
//
//  OPC Trend VC++ Client:	Trend.CPP
//							(Source File)
//
/////////////////////////////////////////////////////////////////////////////
//
//          Author: Raphael Imhof
//    Initial Date: 11/04/98
//       $Workfile: Trend.cpp $
//       $Revision: 1 $
//           $Date: 7/27/99 5:24p $
//   Target System: Microsoft Windows NT 4.0
//     Environment: Visual C++ 5.0 / OPC DataAccess 1.0 / 2.0
//         Remarks: 
//
/////////////////////////////////////////////////////////////////////////////
//
//     Description: Defines the class behaviors for the application
//					
//
/////////////////////////////////////////////////////////////////////////////
//
//  History of Changes     (Please remove very old comments and blank lines!)
//            $Log: /IDK/OPCServer/clients/VC++/Trend/Trend.cpp $
// 
// 1     7/27/99 5:24p Imhof
// 
// 1     7/27/99 5:20p Imhof
// 
// 6     1/15/99 7:04p Imhof
// Updated legal notice.
// 
// 5     12/15/98 10:30a Imhof
// Modifications for OPC 2.0
// 
// 4     11/06/98 5:53p Imhof
// Added header, comment and made some small code changes.
// 
// 
//  $Nokeywords:$ (To avoid useless search while checking in.)
/////////////////////////////////////////////////////////////////////////////
//  Copyright (C) 1998, Siemens Building Technologies, Inc. Landis Division
//
// SIEMENS BUILDING TECHNOLOGIES, INC. IS PROVIDING THE FOLLOWING
// EXAMPLES OF CODE AS SAMPLE ONLY.
//
// SIEMENS BUILDING TECHNOLOGIES, INC.  MAKES NO REPRESENTATIONS
// OR WARRANTIES OF ANY KIND  WITH RESPECT TO THE VALIDTY OF THE 
// CODES   OR   DESIRED   RESULTS   AND   DISCLAIMS   ALL   SUCH 
// REPRESENTATIONS   AND   WARRANTIES,  INCLUDING  FOR  EXAMPLE, 
// WARRANTIES  OF  MERCHANTABILITY  AND FITNESS FOR A PARTICULAR 
// PURPOSE.    SIEMENS  BUILIDNG  TECHNOLOGIES,  INC.  DOES  NOT 
// REPRESENT  OR  WARRANT  THAT  THE  FOLLOWING CODE SAMPLES ARE 
// ACCURATE, VALID, COMPLETE OR CURRENT.
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Trend.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "TrendDoc.h"
#include "TrendListView.h"
#include "AddItemDlg.h"
#include "optionsdlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTrendApp

BEGIN_MESSAGE_MAP(CTrendApp, CWinApp)
	//{{AFX_MSG_MAP(CTrendApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_VIEW_OPTIONS, OnViewOptions)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CTrendApp construction

CTrendApp::CTrendApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
	m_pInfoServer = NULL;
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTrendApp object

CTrendApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CTrendApp initialization

BOOL CTrendApp::InitInstance()
{
	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		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.
	// 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();  // 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.

	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_TRENDTYPE,
		RUNTIME_CLASS(CTrendDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CTrendListView));
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// 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;

	// The main window has been initialized, so show and update it.
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	m_pInfoServer = new CInfoServer;
	
	return TRUE;

}


CInfoServer* CTrendApp::GetInfoServer()
{
	return m_pInfoServer;
}

/////////////////////////////////////////////////////////////////////////////
// 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 CTrendApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CTrendApp commands

int CTrendApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	//should be disconnected by now in CMainFrame::OnDestroy()
	if(m_pInfoServer->IsConnected()) m_pInfoServer->Disconnect();
	delete m_pInfoServer;
	m_pInfoServer = NULL;

	return CWinApp::ExitInstance();
}

void CTrendApp::OnFileOpen() 
{
	// TODO: Add your command handler code here
	CAddItemDlg		dlg;

	USES_CONVERSION;

	if(m_pInfoServer->IsConnected())
	{
		if(IDOK == dlg.DoModal()) 
		{
			OpenDocumentFile(dlg.m_sItemTag);
		}
	}
	else
	{
		AfxMessageBox(IDS_CONNECT_OPC_SERVER_FIRST);
	}
}

CDocument* CTrendApp::OpenDocumentFile(LPCTSTR lpszFileName) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CWinApp::OpenDocumentFile(lpszFileName);
}

//error output wrapping
void CTrendApp::DisplayText(CString sText)
{	
	CMainFrame* pMainFrm = (CMainFrame*)AfxGetMainWnd();

	if(NULL != pMainFrm) //indication that the rich edit has been created
	{
		pMainFrm->GetOutPutBar().DisplayText(sText);
	}
	else
	{
		CString sApp;
		sApp.LoadString(AFX_IDS_APP_TITLE);
		::MessageBox(0, sText, sApp, MB_OK | MB_ICONEXCLAMATION);
	}
}

void CTrendApp::DisplayText(CString sText, HRESULT hr)
{
	CString sError;
	if(COutputBar::GetErrorText(hr, sError))
	{
		sText = sText + _T(" returned: ") + sError;
		DisplayText(sText);
	}
}

void CTrendApp::DisplayText(HRESULT hr)
{
	CString sError;
	if(COutputBar::GetErrorText(hr, sError))
	{
		DisplayText(sError);
	}
}

void CTrendApp::OnViewOptions() 
{
	// TODO: Add your command handler code here
	COptionsDlg dlg;

	dlg.m_iOPCVersion = (int)GetInfoServer()->GetOPCVersion() - 1;

	if(IDOK == dlg.DoModal())
	{
		//update options
		GetInfoServer()->SetOPCVersion((float)dlg.m_iOPCVersion + 1);
	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -