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

📄 mainwnd.cpp

📁 VisualC OPC Client Example C 程序开发
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			if (pServer && !bDisableProjectEditOperations)
				pCmdUI->Enable (!pServer->IsConnected ());
			else
				pCmdUI->Enable (false);
			}
			break;

		// Enable "Tools|Server|Disconnect", "Tools|Server|Reconnect", 
		// "Tools|Server|Get Error String", "Tools|Server|Get Group By Name",
		// and "Tools|Server|Enumerate Groups" if document is not locked,
		// a server is selected, and that server is presently connected:
		case ID_TOOLS_DISCONNECT:
		case ID_TOOLS_RECONNECT:
		case ID_TOOLS_GET_ERROR_STRING:
		case ID_TOOLS_GET_GROUP_BY_NAME:
		case ID_TOOLS_ENUMERATE_GROUPS:
			{
			CKServer *pServer = pDoc->GetSelectedServer ();

			if (pServer && !bDisableProjectEditOperations)
				pCmdUI->Enable (pServer->IsConnected ());
			else
				pCmdUI->Enable (false);
			}
			break;

		// Enable "Tools|Group|Clone Group" if document is not locked, a
		// group is selected, and that group supports the Group State
		// Management interface:
		case ID_TOOLS_CLONE_GROUP:
			{
			CKGroup *pGroup = pDoc->GetSelectedGroup ();
			
			if (pGroup && !bDisableProjectEditOperations)
				{
				pCmdUI->Enable (pGroup->IsIGroupStateMgtSupported ());
				}
			else
				pCmdUI->Enable (false);
			}
			break;

		// Enable "Tools|Group|Export CSV" and "Tools|Group|Import CSV" if
		// document is not locked, and a group is selected:
		case ID_TOOLS_EXPORT_CSV:
		case ID_TOOLS_IMPORT_CSV:
			pCmdUI->Enable (!bDisableProjectEditOperations && pDoc->GetSelectedGroup () != NULL);
			break;

		// Enable "Tools|Item|Set Active" and "Tools|Item|Set Inactive" if
		// docuement is not locked, a group is selected, if one or more
		// items in that group are currently selected, and the group
		// supports the Item Management interface:
		case ID_TOOLS_SET_ACTIVE:
		case ID_TOOLS_SET_INACTIVE:
			{
			CKGroup *pGroup = pDoc->GetSelectedGroup ();
			
			if (pGroup && !bDisableProjectEditOperations)
				{
				pCmdUI->Enable ((GetItemView ()->GetSelectedCount () > 0) && 
					(pGroup->IsIItemMgtSupported ()));
				}
			else
				pCmdUI->Enable (false);
			}
			break;

		// Enable item sync read and write if document is not locked, a
		// group is selected, if one or more items in that group are 
		// currently selected, and the group supports the sync IO
		// interface:
		case ID_TOOLS_SYNC_READ_CACHE:
		case ID_TOOLS_SYNC_READ_DEVICE:
		case ID_TOOLS_SYNC_WRITE:
			{
			CKGroup *pGroup = pDoc->GetSelectedGroup ();
			
			if (pGroup && !bDisableProjectEditOperations)
				{
				pCmdUI->Enable ((GetItemView ()->GetSelectedCount () > 0) && 
					(pGroup->IsISyncIOSupported ()));
				}
			else
				pCmdUI->Enable (false);
			}
			break;

		// Enable item async 1.0 read, write and refresh if document is not
		// locked, a group is selected, if one or more items in that group
		// are currently selected, the group supports the Async IO interface
		// and the OPC_20_DATACHANGE update method:
		case ID_TOOLS_ASYNC10_READ_CACHE:
		case ID_TOOLS_ASYNC10_READ_DEVICE:
		case ID_TOOLS_ASYNC10_REFRESH_CACHE:
		case ID_TOOLS_ASYNC10_REFRESH_DEVICE:
		case ID_TOOLS_ASYNC10_WRITE:
			{
			CKGroup *pGroup = pDoc->GetSelectedGroup ();
			
			if (pGroup && !bDisableProjectEditOperations)
				{
				pCmdUI->Enable ((GetItemView ()->GetSelectedCount () > 0) && 
								(pGroup->IsIAsyncIOSupported ()) &&
								(pGroup->GetUpdateMethod () != OPC_20_DATACHANGE));
				}
			else
				pCmdUI->Enable (false);
			}
			break;

		// Enable item async 2.0 read, write and refresh if document is not
		// locked, a group is selected, if one or more items in that group
		// are currently selected, the group supports the Async 2.0 IO interface
		// and the OPC_20_DATACHANGE update method
		case ID_TOOLS_ASYNC20_READ_DEVICE:
		case ID_TOOLS_ASYNC20_REFRESH_CACHE:
		case ID_TOOLS_ASYNC20_REFRESH_DEVICE:
		case ID_TOOLS_ASYNC20_WRITE:
			{
			CKGroup *pGroup = pDoc->GetSelectedGroup ();
			
			if (pGroup && !bDisableProjectEditOperations)
				{
				pCmdUI->Enable ((GetItemView ()->GetSelectedCount () > 0) && 
								(pGroup->IsIAsyncIO2Supported ()) &&
								(pGroup->GetUpdateMethod () == OPC_20_DATACHANGE));
				}
			else
				pCmdUI->Enable (false);
			}
			break;

		default:
			// Unexpected item ID - programmer error
			TRACE (_T("OTC: Unhandled OnUpdateCmdUI case (%08X)!\r\n"), pCmdUI->m_nID);
			break;
		}
	}

// **************************************************************************
// OnServerShutdownRequest ()
//
// Description:
//	Handles notification that a server has been shutdown.
//
// Parameters:
//  WPARAM		wParam		Not used.
//	LPARAM		lParam		Pointer to server object.
//
// Returns:
//  long - 0.
// **************************************************************************
long CKMainWnd::OnServerShutdownRequest (WPARAM wParam, LPARAM lParam)
	{
	// Get pointer to our document:
	CKDocument *pDoc = (CKDocument *) GetActiveDocument ();
	ASSERT (pDoc != NULL);

	// Notify the document of the shutdown request:
	pDoc->OnServerShutdown ((CKServer *) lParam);

	return (0);
	}

// **************************************************************************
// OnSelectGroup
//
// Description:
//	Handles notification that a group should be selected.
//
// Parameters:
//  WPARAM		wParam		Not used.
//	LPARAM		lParam		Pointer to group object.
//
// Returns:
//  long - 0.
// **************************************************************************
long CKMainWnd::OnSelectGroup (WPARAM wParam, LPARAM lParam)
	{
	// Get pointer to our document:
	CKDocument *pDoc = (CKDocument *) GetActiveDocument ();
	ASSERT (pDoc != NULL);

	// Notify document to update all views due to a new group selection.
	// Pointer to selected group object is passed along as lParam:
	pDoc->UpdateAllViews (NULL, HINT_SELECT_GROUP, (CObject *)lParam);
	
	return (0);
	}

// **************************************************************************
// OnRefreshItemView ()
//
// Description:
//	Handles notification that a item view should be repianted.
//
// Parameters:
//  WPARAM		wParam		Not used.
//	LPARAM		lParam		Not used.
//
// Returns:
//  long - 0.
// **************************************************************************
long CKMainWnd::OnRefreshItemView (WPARAM wParam, LPARAM lParam)
	{
	// Get pointer to our document:
	CKDocument *pDoc = (CKDocument *) GetActiveDocument ();
	ASSERT (pDoc != NULL);

	// Notify document to update item view:
	pDoc->UpdateAllViews (NULL, HINT_REFRESH_ITEMVIEW, NULL);
	
	return (0);
	}

// **************************************************************************
// OnItemReAdd ()
//
// Description:
//	Handles notification that a item should be re-added to the view.
//
// Parameters:
//  WPARAM		wParam		Not used.
//	LPARAM		lParam		Pointer to the item.
//
// Returns:
//  long - 0.
// **************************************************************************
long CKMainWnd::OnItemReAdd (WPARAM wParam,	LPARAM lParam)
	{
	// Get pointer to our document:
	CKDocument *pDoc = (CKDocument *) GetActiveDocument ();
	ASSERT (pDoc != NULL);

	// Notify document to update all views due to a re-add item request.
	// Pointer to item object is passed along as lParam:
	pDoc->UpdateAllViews (NULL, HINT_READD_ITEM, (CObject *)lParam);
	
	// Set document modified flag:
	pDoc->SetModified ();

	return (0);
	}

// **************************************************************************
// OnChangeView ()
//
// Description:
//	Handles notification that the view should be changed (tab selection).
//
// Parameters:
//  WPARAM		wParam			Not used.
//	CView		*pActiveView	Pointer to the active view.
//
// Returns:
//  long - 0.
// **************************************************************************
long CKMainWnd::OnChangeView (WPARAM wParam, CView *pActiveView)
	{
	// See what view pActiveView points to, and set that view active:

	// If group view,
	if (pActiveView == GetGroupView ())
		SetActiveView (GetItemView ());
	
	// else if item view,
	else if (pActiveView == GetItemView ())
		SetActiveView (GetEventView ());

	// else if event view (no other case expected),
	else if (pActiveView == GetEventView ())
		SetActiveView (GetGroupView ());

	return (0);
	}

// **************************************************************************
// LogMsg ()
//
// Description:
//	Called to place a message in the event log.
//
// Parameters:
//  EVENTTYPE	eType			Event type (enumerated in globals.h)
//	LPCTSTR		lpszMessage		Pointer to message string.
//
// Returns:
//  void
// **************************************************************************
void CKMainWnd::LogMsg (EVENTTYPE eType, LPCTSTR lpszMessage)
	{
	// Pass the message along to the event view:
	GetEventView ()->LogMsg (eType, lpszMessage);
	}

// **************************************************************************
// UpdateItemCount ()
//
// Description:
//	Called to update the item count member variable (m_cnItems).
//
// Parameters:
//  int			nDelta		Number to change the count by.
//
// Returns:
//  void
// **************************************************************************
void CKMainWnd::UpdateItemCount (int nDelta)
	{
	// Create a CSafeLock to make this object thread safe.  Our critical
	// section gets locked here, and will automatically be unlocked when the
	// CSafeLock goes out of scope.
	CSafeLock cs (&m_csStatus);

	// Update the item count:
	m_cnItems += nDelta;
	ASSERT (m_cnItems >= 0);
	}

// **************************************************************************
// SetStatusBarText ()
//
// Description:
//	Called to set the status bar text.
//
// Parameters:
//  LPCTSTR		lpszText	Pointer to text string.
//
// Returns:
//  void
// **************************************************************************
void CKMainWnd::SetStatusBarText (LPCTSTR lpszText)
	{
	// Create a CSafeLock to make this object thread safe.  Our critical
	// section gets locked here, and will automatically be unlocked when the
	// CSafeLock goes out of scope.
	CSafeLock cs (&m_csStatus);

	// Store the text:
	m_strStatusText = lpszText;

	// Set flag to force a status bar update (to be processed in OnTimer()):
	m_bForceStatusText = true;
	}

// **************************************************************************
// OnTimer ()
//
// Description:
//	Timer event handler.  Do periodic maintenance of view.
//
// Parameters:
//	UINT		nIDEvent		Timer event type.
//
// Returns:
//  void
// **************************************************************************
void CKMainWnd::OnTimer (UINT nIDEvent) 
	{
	// Process our status update event:
	if (nIDEvent == STATUSUPDATETIMER)
		{
		// Create a CSafeLock to make this object thread safe.  Our critical
		// section gets locked here, and will automatically be unlocked when the
		// CSafeLock goes out of scope.
		CSafeLock cs (&m_csStatus);

		static TCHAR szBuff [128];
		static CString strItemCount;
		static int cnItems = -1;

		// Only update on item change:
		if (cnItems != m_cnItems)
			{
			cnItems = m_cnItems;

			// Initialize string once:
			if (strItemCount.IsEmpty ())
				strItemCount.LoadString (IDS_ITEMCOUNT);

			// Update item count string:
			wsprintf (szBuff, strItemCount, cnItems);

			// Calculate new size for the pane:
			CClientDC dc (NULL);
			
			HFONT hFont = (HFONT)m_cStatusBar.SendMessage (WM_GETFONT);
			HGDIOBJ hOldFont = NULL;
			
			if (hFont != NULL)
				hOldFont = dc.SelectObject (hFont);

			CSize sz = dc.GetTextExtent (szBuff, lstrlen (szBuff));
			
			if (hOldFont != NULL)
				dc.SelectObject (hOldFont);

			// Update the width:
			m_cStatusBar.SetPaneInfo (ID_ITEMCOUNT, auIDs[ID_ITEMCOUNT], SBPS_NORMAL, sz.cx);

			// Update pane text:
			m_cStatusBar.SetPaneText (ID_ITEMCOUNT, szBuff, true);
			}

		// Reset status bar text if force update flag is set or if
		// current text is not "Idle"
		if (m_bForceStatusText || m_strIdleStatusText != m_strStatusText)
			{
			m_cStatusBar.SetPaneText (ID_HELPTEXT, m_strStatusText, true);
			m_bForceStatusText = false;
			}
		}

	// Perform default processing for all other timer event types:
	CFrameWnd::OnTimer (nIDEvent);
	}

// **************************************************************************
// OnDestroy ()
//
// Description:
//	The framework calls this member function to inform the CWnd object that 
//	it is being destroyed. OnDestroy is called after the CWnd object is 
//	removed from the screen.  Use opportunity to kill timer.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKMainWnd::OnDestroy () 
	{
	KillTimer (STATUSUPDATETIMER);
	CFrameWnd::OnDestroy ();
	}

⌨️ 快捷键说明

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