📄 serverpropertysheet.cpp
字号:
strLoader.FormatMessage (IDS_VENDORNAME, szBuffer);
strStatus += strLoader;
// Free memory allocated for vender info:
CoTaskMemFree (pServerStatus->szVendorInfo);
}
// Add start time to status string:
if (FileTimeToLocalFileTime (&pServerStatus->ftStartTime, &ftLocal))
{
SYSTEMTIME systime;
if (FileTimeToSystemTime (&ftLocal, &systime))
{
strTemp.Format (_T("%02d:%02d:%02d:%03d"), systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds);
strLoader.FormatMessage (IDS_STARTTIME, strTemp);
strStatus += strLoader;
}
}
// Add current time to status string:
if (FileTimeToLocalFileTime (&pServerStatus->ftCurrentTime, &ftLocal))
{
SYSTEMTIME systime;
if (FileTimeToSystemTime (&ftLocal, &systime))
{
strTemp.Format (_T("%02d:%02d:%02d:%03d"), systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds);
strLoader.FormatMessage (IDS_CURRENTTIME, strTemp);
strStatus += strLoader;
}
}
// Add last update time to status string:
if (FileTimeToLocalFileTime (&pServerStatus->ftLastUpdateTime, &ftLocal))
{
SYSTEMTIME systime;
if (FileTimeToSystemTime (&ftLocal, &systime))
{
strTemp.Format (_T("%02d:%02d:%02d:%03d"), systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds);
strLoader.FormatMessage (IDS_LASTUPDATETIME, strTemp);
strStatus += strLoader;
}
}
// Create a string describing server state:
switch (pServerStatus->dwServerState)
{
case OPC_STATUS_RUNNING:
strTemp.LoadString (IDS_RUNNING);
strLoader.FormatMessage (IDS_SERVERSTATE, strTemp);
break;
case OPC_STATUS_FAILED:
strTemp.LoadString (IDS_FAILED);
strLoader.FormatMessage (IDS_SERVERSTATE, strTemp);
break;
case OPC_STATUS_NOCONFIG:
strTemp.LoadString (IDS_NOCONFIG);
strLoader.FormatMessage (IDS_SERVERSTATE, strTemp);
break;
case OPC_STATUS_SUSPENDED:
strTemp.LoadString (IDS_SUSPENDED);
strLoader.FormatMessage (IDS_SERVERSTATE, strTemp);
break;
case OPC_STATUS_TEST:
strTemp.LoadString (IDS_TEST);
strLoader.FormatMessage (IDS_SERVERSTATE, strTemp);
break;
default:
strLoader.FormatMessage (IDS_SERVERSTATE, _T("???"));
break;
}
// Add server state to status string:
strStatus += strLoader;
// Add group count to status string:
strTemp.Format (_T("%d"), pServerStatus->dwGroupCount);
strLoader.FormatMessage (IDS_GROUPCOUNT, strTemp);
strStatus += strLoader;
// Add major version number to status string:
strTemp.Format (_T("%d"), pServerStatus->wMajorVersion);
strLoader.FormatMessage (IDS_MAJORVERSION, strTemp);
strStatus += strLoader;
// Add minor version to status string:
strTemp.Format (_T("%d"), pServerStatus->wMinorVersion);
strLoader.FormatMessage (IDS_MINORVERSION, strTemp);
strStatus += strLoader;
// Add build number to status string:
strTemp.Format (_T("%d"), pServerStatus->wBuildNumber);
strLoader.FormatMessage (IDS_BUILDNUMBER, strTemp);
strStatus += strLoader;
// Free memeory allocated for server status:
CoTaskMemFree (pServerStatus);
}
// Else if failed, add string stating unable to determin server status
// to status string:
else
{
strLoader.LoadString (IDS_UNABLE_TO_DETERMINE_STATUS);
strStatus += strLoader;
}
// Display the status string:
((CStatic *) GetDlgItem (IDC_STATUS))->SetWindowText (strStatus);
// return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
return (TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// CKServerInterfacesPage property page
/////////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE (CKServerInterfacesPage, CPropertyPage)
// **************************************************************************
BEGIN_MESSAGE_MAP (CKServerInterfacesPage, CPropertyPage)
//{{AFX_MSG_MAP(CKServerInterfacesPage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP ()
// **************************************************************************
// CKServerInterfacesPage ()
//
// Description:
// Constructor.
//
// Parameters:
// none
//
// Returns:
// none
// **************************************************************************
CKServerInterfacesPage::CKServerInterfacesPage () : CPropertyPage (CKServerInterfacesPage::IDD)
{
// Initialize member variables:
//{{AFX_DATA_INIT(CKServerInterfacesPage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pServer = NULL;
}
// **************************************************************************
// ~CKServerInterfacesPage ()
//
// Description:
// Destructor.
//
// Parameters:
// none
//
// Returns:
// none
// **************************************************************************
CKServerInterfacesPage::~CKServerInterfacesPage ()
{
}
// **************************************************************************
// 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 CKServerInterfacesPage::DoDataExchange (CDataExchange *pDX)
{
// Perform default processing:
CPropertyPage::DoDataExchange (pDX);
// Exchange data between controls and associated member variables:
//{{AFX_DATA_MAP(CKServerInterfacesPage)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
/////////////////////////////////////////////////////////////////////////////
// CKServerInterfacesPage message handlers
/////////////////////////////////////////////////////////////////////////////
#define NUMGROUPINTERFACES 7 // currently 7 possible interfaces at the server level
// **************************************************************************
// OnInitDialog ()
//
// Description:
// Called immediately before the dialog box is displayed. Use opportunity
// to initialize controls.
//
// Parameters:
// none
//
// Returns:
// BOOL - TRUE.
// **************************************************************************
BOOL CKServerInterfacesPage::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);
// Create interface column:
strLoader.LoadString (IDS_INTERFACE);
pList->InsertColumn (0, strLoader, LVCFMT_LEFT, 200);
// Create required column:
strLoader.LoadString (IDS_REQUIRED);
pList->InsertColumn (1, strLoader, LVCFMT_LEFT, 75);
// Creaete supported column:
strLoader.LoadString (IDS_SUPPORTED);
pList->InsertColumn (2, strLoader, LVCFMT_LEFT, 75);
// The server had better have been set by now (check for debug):
ASSERT (m_pServer != NULL);
// Load "Yes" and "No" strings from string resources:
strNo.LoadString (IDS_NO);
strYes.LoadString (IDS_YES);
// Loop over interfaces and set list control items (one per interface):
nIndex = 0;
while (nIndex < NUMGROUPINTERFACES)
{
switch (nIndex)
{
case 0:
// IOPCServer:
pList->InsertItem (nIndex, _T ("IOPCServer"), ILI_INTERFACE); // interface
pList->SetItemText (nIndex, 1, strYes); // required
pList->SetItemText (nIndex, 2,
m_pServer->IsIServerSupported () ? strYes : strNo); // supported
break;
case 1:
// IOPCBrowseServerAddressSpace:
pList->InsertItem (nIndex, _T ("IOPCBrowseServerAddressSpace"), ILI_INTERFACE);
pList->SetItemText (nIndex, 1, strNo);
pList->SetItemText (nIndex, 2,
m_pServer->IsIBrowsingSupported () ? strYes : strNo);
break;
case 2:
// IOPCServerPublicGroups:
pList->InsertItem (nIndex, _T ("IOPCServerPublicGroups"), ILI_INTERFACE);
pList->SetItemText (nIndex, 1, strNo);
pList->SetItemText (nIndex, 2,
m_pServer->IsIServerPublicGroupsSupported () ? strYes : strNo);
break;
case 3:
// IPersistFile:
pList->InsertItem (nIndex, _T ("IPersistFile"), ILI_INTERFACE);
pList->SetItemText (nIndex, 1, strNo);
pList->SetItemText (nIndex, 2,
m_pServer->IsIPersistFileSupported () ? strYes : strNo);
break;
case 4:
// IOPCCommon:
pList->InsertItem (nIndex, _T ("IOPCCommon (2.0 only)"), ILI_INTERFACE);
pList->SetItemText (nIndex, 1, strYes);
pList->SetItemText (nIndex, 2,
m_pServer->IsICommonSupported () ? strYes : strNo);
break;
case 5:
// IOPCItemProperties:
pList->InsertItem (nIndex, _T ("IOPCItemProperties (2.0 only)"), ILI_INTERFACE);
pList->SetItemText (nIndex, 1, strYes);
pList->SetItemText (nIndex, 2,
m_pServer->IsIItemPropertiesSupported () ? strYes : strNo);
break;
case 6:
// IConnectionPointContainer:
pList->InsertItem (nIndex, _T ("IConnectionPointContainer (2.0 only)"), ILI_INTERFACE);
pList->SetItemText (nIndex, 1, strYes);
pList->SetItemText (nIndex, 2,
m_pServer->IsIConnectionPointContainerSupported () ? strYes : strNo);
break;
default:
// Unexpected interface index - programmer error:
ASSERT (FALSE);
break;
}
// Increment interface index:
nIndex++;
}
// return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
return (TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// CKServerPropertySheet
/////////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC (CKServerPropertySheet, CPropertySheet)
// **************************************************************************
BEGIN_MESSAGE_MAP (CKServerPropertySheet, CPropertySheet)
//{{AFX_MSG_MAP(CKServerPropertySheet)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP ()
// **************************************************************************
// CKServerPropertySheet
//
// Description:
// Constructor.
//
// Parameters:
// CKServer *pServer Pointer to server object.
//
// Returns:
// none
// **************************************************************************
CKServerPropertySheet::CKServerPropertySheet (CKServer *pServer)
: CPropertySheet (IDS_SERVER_PROPERTIES)
{
// Initialize member variables:
m_pServer = pServer;
// Add general page if they are selecting a new server (indicated by
// NULL server pointer):
if (m_pServer == NULL)
{
AddPage (&m_cGeneralPage);
}
// Else add status and interface pages if they are selected an existing
// server:
else
{
// Add status page:
m_cStatusPage.m_pServer = m_pServer;
AddPage (&m_cStatusPage);
// Add interface page:
m_cInterfacePage.m_pServer = m_pServer;
AddPage (&m_cInterfacePage);
}
// Remove apply button since there will be nothing to change:
m_psh.dwFlags |= PSH_NOAPPLYNOW;
}
// **************************************************************************
// ~CKServerPropertySheet ()
//
// Description:
// Destructor.
//
// Parameters:
// none
//
// Returns:
// none
// **************************************************************************
CKServerPropertySheet::~CKServerPropertySheet ()
{
}
/////////////////////////////////////////////////////////////////////////////
// CKServerPropertySheet message handlers
/////////////////////////////////////////////////////////////////////////////
// **************************************************************************
// DoModal ()
//
// Description:
// Override of CPropertySheet::DoModal function to give us a change to
// create a new CKServer object if needed and attempt to connect to
// associated OPC server.
//
// Parameters:
// none
//
// Returns:
// void
// **************************************************************************
int CKServerPropertySheet::DoModal ()
{
// Allow for default processing. Save return value:
int nRC = CPropertySheet::DoModal ();
// If we are already connected to a server, reset return code to
// IDCANCEL so no changes will be applied.
if (m_pServer)
nRC = IDCANCEL;
// If the user selects OK, and the server is a new connection, add server
// and attempt a connection:
if (nRC == IDOK)
{
// Create a new server is server pointer is currently NULL:
if (m_pServer == NULL)
{
try
{
m_pServer = new CKServer;
}
catch (...)
{
// Memory allocation error. Reset return code to IDCANCEL
// so no changes will be applied:
ASSERT (FALSE);
m_pServer = NULL;
nRC = IDCANCEL;
}
}
// Attempt to connect to a server:
if (m_pServer)
{
m_pServer->Connect (
m_cGeneralPage.m_strProgID,
m_cGeneralPage.m_strRemoteMachine);
}
}
// Return the return code:
return (nRC);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -