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

📄 mainfrm.cpp

📁 此文件为VC++开发环境下的OPC client trend 源代码
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////
//
//  OPC Trend VC++ Client:	MainFrm.CPP
//							(Source File)
//
/////////////////////////////////////////////////////////////////////////////
//
//          Author: Raphael Imhof
//    Initial Date: 11/04/98
//       $Workfile: MainFrm.cpp $
//       $Revision: 2 $
//           $Date: 5/02/01 6:39p $
//   Target System: Microsoft Windows NT 4.0
//     Environment: Visual C++ 5.0 / OPC DataAccess 1.0 / 2.0
//         Remarks: 
//
/////////////////////////////////////////////////////////////////////////////
//
//     Description: implementation of the CMainFrame class
//					
//
/////////////////////////////////////////////////////////////////////////////
//
//  History of Changes     (Please remove very old comments and blank lines!)
//            $Log: /IDK/OPCServer/clients/VC++/Trend/MainFrm.cpp $
// 
// 2     5/02/01 6:39p Schmickley
// Corrections to allow running under VC 6.0 debug.
// 
// 1     7/27/99 5:24p Imhof
// 
// 1     7/27/99 5:19p Imhof
// 
// 7     2/08/99 7:21p Imhof
// Added menu item under view for show/hide the output bar.
// 
// 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"


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

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_MESSAGE(WM_SHUTDOWN_MSG, OnShutdownMsg)
	ON_COMMAND(ID_VIEW_DOCKINGDIALOGBAR, OnViewDockingdialogbar)
	ON_COMMAND(ID_TREND_CONNECT, OnTrendConnect)
	ON_UPDATE_COMMAND_UI(ID_TREND_CONNECT, OnUpdateTrendConnect)
	ON_COMMAND(ID_TREND_DISCONNECT, OnTrendDisconnect)
	ON_UPDATE_COMMAND_UI(ID_TREND_DISCONNECT, OnUpdateTrendDisconnect)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_SERVERSTATE, OnUpdateServerState)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_SERVER, OnUpdateServer)
	ON_WM_DESTROY()
	ON_UPDATE_COMMAND_UI(ID_VIEW_DOCKINGDIALOGBAR, OnUpdateViewDockingdialogbar)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
	ID_INDICATOR_SERVER,	//server name
	ID_INDICATOR_SERVERSTATE, //server state: disconnected/connected
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.Create(this) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Remove this if you don't want tool tips or a resizeable toolbar
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

	
	//output bar
	if (!m_wndOutputBar.Create(this, &m_OutPutBarDlg, CString("Output Bar"), IDD_OUTPUTBAR, CBRS_FLOAT_MULTI | CBRS_ALIGN_ANY | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
	{
		TRACE0("Failed to create dialogbar\n");
		return -1;      // fail to create
	}
	
	
	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	m_wndOutputBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	ShowControlBar(&m_wndOutputBar, TRUE, FALSE);
	DockControlBar(&m_wndOutputBar, AFX_IDW_DOCKBAR_BOTTOM );

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CMDIFrameWnd::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CMDIFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CMDIFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CMDIFrameWnd::OnCreateClient(lpcs, pContext);
}

void CMainFrame::OnViewDockingdialogbar() 
{
	// TODO: Add your command handler code here
	ShowControlBar(&m_wndOutputBar, (m_wndOutputBar.GetStyle() & WS_VISIBLE) == 0, FALSE);

	//most common use
	DockControlBar(&m_wndOutputBar, AFX_IDW_DOCKBAR_BOTTOM );
	
}

void CMainFrame::OnUpdateViewDockingdialogbar(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck((m_wndOutputBar.GetStyle() & WS_VISIBLE) != 0);
}

COutputBar& CMainFrame::GetOutPutBar()
{
	return m_OutPutBarDlg;
}

void CMainFrame::OnTrendConnect() 
{
	// TODO: Add your command handler code here
	CInfoServer* pInfoServer = ((CTrendApp*)AfxGetApp())->GetInfoServer();

	if(pInfoServer != NULL)
	{
		if(pInfoServer->ChooseServer())
		{
			if(pInfoServer->Connect())
			{
				//create group
				CGroup*	pGroup = NULL;
				pInfoServer->AddGroup(&pGroup);
			}
		}
	}
}

void CMainFrame::OnUpdateTrendConnect(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CInfoServer* pInfoServer = ((CTrendApp*)AfxGetApp())->GetInfoServer();

	if(pInfoServer != NULL)
		pCmdUI->Enable(!pInfoServer->IsConnected());
	else
		pCmdUI->Enable(FALSE);
}

void CMainFrame::OnTrendDisconnect() 
{
	// TODO: Add your command handler code here
	CInfoServer* pInfoServer = ((CTrendApp*)AfxGetApp())->GetInfoServer();

	if(pInfoServer != NULL)
	{
		if(pInfoServer->Disconnect())
		{
			//close all windows
			AfxGetApp()->CloseAllDocuments(FALSE);
		}
	}
}

void CMainFrame::OnUpdateTrendDisconnect(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CInfoServer* pInfoServer = ((CTrendApp*)AfxGetApp())->GetInfoServer();

	if(pInfoServer != NULL)
		pCmdUI->Enable(pInfoServer->IsConnected());
	else
		pCmdUI->Enable(FALSE);
}

void CMainFrame::OnUpdateServerState(CCmdUI *pCmdUI)
{
    pCmdUI->Enable(); 

	if(((CTrendApp*)AfxGetApp())->GetInfoServer() != NULL)
	{
		if(((CTrendApp*)AfxGetApp())->GetInfoServer()->IsConnected())
			pCmdUI->SetText(_T("Connected"));
		else
			pCmdUI->SetText(_T("Disconnected"));
	}
	else
	{
		pCmdUI->SetText(_T("Disconnected"));
	}
}

void CMainFrame::OnUpdateServer(CCmdUI *pCmdUI)
{
    pCmdUI->Enable(); 

	if(((CTrendApp*)AfxGetApp())->GetInfoServer() != NULL)
	{
		if(((CTrendApp*)AfxGetApp())->GetInfoServer()->IsConnected())
			pCmdUI->SetText(((CTrendApp*)AfxGetApp())->GetInfoServer()->GetOPCServerName());
		else
			pCmdUI->SetText(_T("\\"));
	}
	else
	{
		pCmdUI->SetText(_T("Disconnected"));
	}
}

void CMainFrame::OnDestroy() 
{
	CInfoServer* pInfoServer = ((CTrendApp*)AfxGetApp())->GetInfoServer();

	if(pInfoServer != NULL)
	{
		//if(pInfoServer->IsConnected())
		pInfoServer->Disconnect();  //in order to call the ShutdownRequest::Term() always
	}
	
	CMDIFrameWnd::OnDestroy();
	
	// TODO: Add your message handler code here
}

/////////////////////////////////////////////////////////////////////////////
// User defined messages handlers

LONG CMainFrame::OnShutdownMsg(UINT wparam ,LONG lparam)
{
	const CString szMsg = _T("Server is about to shut down for the following reason: ");
	
	//here instead of in COPCShutDownRequest::ShutdownRequest() to avoid a critical section.
	CInfoServer* pInfoServer = NULL;
	CTrendApp* pApp = (CTrendApp*) AfxGetApp();
	pInfoServer = pApp->GetInfoServer();

	if(pInfoServer != NULL)
	{
		pInfoServer->SetConnected(FALSE);
	}

	AfxMessageBox((LPCTSTR) (szMsg + m_sLastShutdownReason));

	m_sLastShutdownReason = _T("");

	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// Members

void CMainFrame::SetLastShutdownReason(LPCWSTR szReason)
{
	USES_CONVERSION;

	m_sLastShutdownReason = OLE2A(szReason);
}

⌨️ 快捷键说明

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