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

📄 grouppropertysheet.cpp

📁 PC客户和opc通信的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// **************************************************************************
// grouppropertysheet.cpp
//
// Description:
//	Implements a property sheet class and associated propety page classes for
//	OPC group properties.
//
// DISCLAIMER:
//	This programming example is provided "AS IS".  As such Kepware, Inc.
//	makes no claims to the worthiness of the code and does not warranty
//	the code to be error free.  It is provided freely and can be used in
//	your own projects.  If you do find this code useful, place a little
//	marketing plug for Kepware in your code.  While we would love to help
//	every one who is trying to write a great OPC client application, the 
//	uniqueness of every project and the limited number of hours in a day 
//	simply prevents us from doing so.  If you really find yourself in a
//	bind, please contact Kepware's technical support.  We will not be able
//	to assist you with server related problems unless you are using KepServer
//	or KepServerEx.
// **************************************************************************


#include "stdafx.h"
#include "opctestclient.h"
#include "grouppropertysheet.h"
#include "server.h"
#include "group.h"

// Image list indices:
#define ILI_INTERFACE		2

// Default group name if the server does not provide a name:
#define DEFAULTGROUPNAME	_T("Group0")


/////////////////////////////////////////////////////////////////////////////
// CKGroupGeneralPage property page
/////////////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNCREATE (CKGroupGeneralPage, CPropertyPage)

// **************************************************************************
BEGIN_MESSAGE_MAP (CKGroupGeneralPage, CPropertyPage)
	//{{AFX_MSG_MAP(CKGroupGeneralPage)
	ON_BN_CLICKED (IDC_ACTIVE, OnChange)
	ON_EN_CHANGE (IDC_LANGUAGEID, OnChange)
	ON_EN_CHANGE (IDC_NAME, OnChange)
	ON_EN_CHANGE (IDC_PERCENTDEADBAND, OnChange)
	ON_EN_CHANGE (IDC_TIMEBIAS, OnChange)
	ON_EN_CHANGE (IDC_UPDATERATE, OnChange)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP ()


// **************************************************************************
// CKGroupGeneralPage ()
//
// Description:
//	Constructor
//
// Parameters:
//  none
//
// Returns:
//  none
// **************************************************************************
CKGroupGeneralPage::CKGroupGeneralPage () : CPropertyPage (CKGroupGeneralPage::IDD)
	{
	// Initialize member variables:

	//{{AFX_DATA_INIT(CKGroupGeneralPage)
	m_bActive		= GROUP_DEFAULT_ACTIVESTATE;
	m_dwLanguageID	= GROUP_DEFAULT_LANGUAGEID;
	m_strName		= GROUP_DEFAULT_NAME;
	m_fDeadband		= GROUP_DEFAULT_DEADBAND;
	m_lBias			= GROUP_DEFAULT_TIMEBIAS;
	m_dwUpdateRate	= GROUP_DEFAULT_UPDATERATE;
	m_nUpdateMethod = GROUP_DEFAULT_UPDATEMETHOD;
	//}}AFX_DATA_INIT

	m_bModified = false;
	}

// **************************************************************************
// ~CKGroupGeneralPage ()
//
// Description:
//	Destructor
//
// Parameters:
//  none
//
// Returns:
//  none
// **************************************************************************
CKGroupGeneralPage::~CKGroupGeneralPage ()
	{
	}

// **************************************************************************
// DoDataExchange ()
//
// Description:
//	This method is called by the framework to exchange and validate dialog data.
//
// Parameters:
//  CDataExchange	*pDX		A pointer to a CDataExchange object.
//
// Returns:
//  void
// **************************************************************************
void CKGroupGeneralPage::DoDataExchange (CDataExchange *pDX)
	{
	// Perform default processing:
	CPropertyPage::DoDataExchange (pDX);

	// Exchange data between controls and associated member variables:
	//{{AFX_DATA_MAP(CKGroupGeneralPage)
	DDX_Check (pDX, IDC_ACTIVE, m_bActive);
	DDX_Text (pDX, IDC_LANGUAGEID, m_dwLanguageID);
	DDV_MinMaxDWord (pDX, m_dwLanguageID, 0, 4294967295);
	DDX_Text (pDX, IDC_NAME, m_strName);
	DDX_Text (pDX, IDC_PERCENTDEADBAND, m_fDeadband);
	DDV_MinMaxFloat (pDX, m_fDeadband, 0.f, 100.f);
	DDX_Text (pDX, IDC_TIMEBIAS, m_lBias);
	DDV_MinMaxLong (pDX, m_lBias, 0, 2147483647);
	DDX_CBIndex (pDX, IDC_UPDATENOTIFICATION, m_nUpdateMethod);
	DDX_Text (pDX, IDC_UPDATERATE, m_dwUpdateRate);
	DDV_MinMaxDWord (pDX, m_dwUpdateRate, 0, 4294967295);
	//}}AFX_DATA_MAP
	}


/////////////////////////////////////////////////////////////////////////////
// CKGroupGeneralPage message handlers
/////////////////////////////////////////////////////////////////////////////

// **************************************************************************
// OnInitDialog ()
//
// Description:
//	Called by framework immediately before the dialog box is displayed,
//
// Parameters:
//  none
//
// Returns:
//  BOOL - TRUE.
// **************************************************************************
BOOL CKGroupGeneralPage::OnInitDialog () 
	{
	// Perform default processing:
	CPropertyPage::OnInitDialog ();
	
	// Subclass our numeric controls for character filtering:
	m_cLangIDEdit.SubclassDlgItem (IDC_LANGUAGEID, this);
	m_cDeadbandEdit.SubclassDlgItem (IDC_PERCENTDEADBAND, this);
	m_cBiasEdit.SubclassDlgItem (IDC_TIMEBIAS, this);
	m_cUpdateRateEdit.SubclassDlgItem (IDC_UPDATERATE, this);

	// return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
	return (TRUE); 
	}

// **************************************************************************
// OnOK ()
//
// Description:
//	Called when the user clicks the OK button.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKGroupGeneralPage::OnOK () 
	{
	// Force a data exchange between controls and member variables:
	// (Take data from controls and us it to set member variables.)
	UpdateData (TRUE);
	}

// **************************************************************************
// OnChange ()
//
// Description:
//	Called by framework when user modifies data attached to a control.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKGroupGeneralPage::OnChange () 
	{
	// Set our local modified flag:
	m_bModified = true;

	// Set base class modified flag.  This will enable the "Apply" button.
	SetModified (TRUE);
	}


/////////////////////////////////////////////////////////////////////////////
// CKGroupInterfacesPage property page
/////////////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNCREATE (CKGroupInterfacesPage, CPropertyPage)

// **************************************************************************
BEGIN_MESSAGE_MAP (CKGroupInterfacesPage, CPropertyPage)
	//{{AFX_MSG_MAP(CKGroupInterfacesPage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP ()


// **************************************************************************
// CKGroupInterfacesPage ()
//
// Description:
//	Constructor
//
// Parameters:
//  none
//
// Returns:
//  none
// **************************************************************************
CKGroupInterfacesPage::CKGroupInterfacesPage () : CPropertyPage (CKGroupInterfacesPage::IDD)
	{
	// Initialize member variables:

	//{{AFX_DATA_INIT(CKGroupInterfacesPage)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	
	m_pGroup = NULL;
	}

// **************************************************************************
// ~CKGroupInterfacesPage ()
//
// Description:
//	Destructor
//
// Parameters:
//  none
//
// Returns:
//  none
// **************************************************************************
CKGroupInterfacesPage::~CKGroupInterfacesPage ()
	{
	}

// **************************************************************************
// DoDataExchange ()
//
// Description:
//	This method is called by the framework to exchange and validate dialog data.
//
// Parameters:
//  CDataExchange	*pDX		A pointer to a CDataExchange object.
//
// Returns:
//  void
// **************************************************************************
void CKGroupInterfacesPage::DoDataExchange (CDataExchange *pDX)
	{
	// Perform default processing:
	CPropertyPage::DoDataExchange (pDX);

	// Exchange data between controls and associated member variables:
	//{{AFX_DATA_MAP(CKGroupInterfacesPage)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
	}


/////////////////////////////////////////////////////////////////////////////
// CKGroupInterfacesPage message handlers
/////////////////////////////////////////////////////////////////////////////

// Define number of possible interfaces at the group level (currently 8).
#define NUMGROUPINTERFACES	8

// **************************************************************************
// OnInitDialog ()
//
// Description:
//	Called by framework immediately before the dialog box is displayed,
//
// Parameters:
//  none
//
// Returns:
//  BOOL - TRUE.
// **************************************************************************
BOOL CKGroupInterfacesPage::OnInitDialog () 
	{
	CListCtrl *pList = NULL;
	CString strLoader;
	CString strYes;
	CString strNo;
	int nIndex;

	// Perform default processing:
	CPropertyPage::OnInitDialog ();

	// Get a pointer to our list control:
	pList = (CListCtrl *) GetDlgItem (IDC_LIST);
	ASSERT (pList != NULL);

	// Initialize the image list for the interfaces. The bitmap must use a 
	// purple background color, RGB (255, 0, 255), so that the CImageList
	// object can construct a mask.  The images are 16x16 pixels.  Set the
	// image list background color to CLR_NONE so masked pixels will be
	// transparent. 
	// Image number		Use
	//	0				not used
	//	1				not used
	//	2				Interface
	m_cImageList.Create (IDB_COMPONENTS, 16, 4, RGB (255, 0, 255));
	m_cImageList.SetBkColor (CLR_NONE);
	pList->SetImageList (&m_cImageList, LVSIL_SMALL);

	// Insert our columns and headings:

	// Interface column:
	strLoader.LoadString (IDS_INTERFACE);
	pList->InsertColumn (0, strLoader, LVCFMT_LEFT, 200);

	// Reguired column:
	strLoader.LoadString (IDS_REQUIRED);
	pList->InsertColumn (1, strLoader, LVCFMT_LEFT, 75);

	// Supported column:
	strLoader.LoadString (IDS_SUPPORTED);
	pList->InsertColumn (2, strLoader, LVCFMT_LEFT, 75);

	// The group should have been set by now:
	ASSERT (m_pGroup != NULL);

	// Insert the interface data:

	// First load "Yes" and "No" string resources:
	strNo.LoadString (IDS_NO);
	strYes.LoadString (IDS_YES);

	// Loop over all interfaces:
	nIndex = 0;
	while (nIndex < NUMGROUPINTERFACES)
		{
		switch (nIndex)
			{
			// IOPCGroupStateMgt
			case 0:
				// Insert interface item in list control:
				pList->InsertItem (nIndex, _T ("IOPCGroupStateMgt"), ILI_INTERFACE);
				
				// Set required field:
				pList->SetItemText (nIndex, 1, strYes);
				
				// Set supported field:
				pList->SetItemText (nIndex, 2, 
					m_pGroup->IsIGroupStateMgtSupported () ? strYes : strNo);
				break;

			// IOPCPublicGroupStateMgt
			case 1:
				// Insert interface item in list control:
				pList->InsertItem (nIndex, _T ("IOPCPublicGroupStateMgt"), ILI_INTERFACE);
				
				// Set required field:
				pList->SetItemText (nIndex, 1, strNo);						

				// Set supported field:
				pList->SetItemText (nIndex, 2, 
					m_pGroup->IsIPublicGroupStateMgtSupported () ? strYes : strNo);
				break;

			// IItemMgt
			case 2:
				// Insert interface item in list control:
				pList->InsertItem (nIndex, _T ("IOPCItemMgt"), ILI_INTERFACE);	
				
				// Set required field:
				pList->SetItemText (nIndex, 1, strYes);					

				// Set supported field:
				pList->SetItemText (nIndex, 2, 
					m_pGroup->IsIItemMgtSupported () ? strYes : strNo);
				break;

			// IOPCSyncIO
			case 3:
				// Insert interface item in list control:
				pList->InsertItem (nIndex, _T ("IOPCSyncIO"), ILI_INTERFACE);

				// Set required field:
				pList->SetItemText (nIndex, 1, strYes);					

				// Set supported field:
				pList->SetItemText (nIndex, 2, 
					m_pGroup->IsISyncIOSupported () ? strYes : strNo);				
				break;

			// IOPCAsyncIO
			case 4:
				// Insert interface item in list control:
				pList->InsertItem (nIndex, _T ("IOPCAsyncIO"), ILI_INTERFACE);
				
				// Set required field:
				pList->SetItemText (nIndex, 1, strYes);					

				// Set supported field:
				pList->SetItemText (nIndex, 2, 

⌨️ 快捷键说明

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