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

📄 groupview.cpp

📁 KepWare的OPC Client 示例.面向C
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	// did not get properly attached to document):
	CKDocument *pDoc = (CKDocument *) GetDocument ();

	// If poiner looks good, tell document to add a server:
	if (pDoc)
		pDoc->AddServer ();
	}

// **************************************************************************
// OnNewGroup ()
//
// Description:
//	New group menu event handler.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKGroupView::OnNewGroup () 
	{
	// Get pointer to our document object.  (Pointer will be NULL if we
	// did not get properly attached to document):
	CKDocument *pDoc = (CKDocument *) GetDocument ();

	// If pointer looks good, tell document to add a group:
	if (pDoc)
		pDoc->AddGroup ();
	}

// **************************************************************************
// OnProperties ()
//
// Description:
//	Properties menu event handler.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKGroupView::OnProperties () 
	{
	// Get reference to out tree control:
	CTreeCtrl &cTree = GetTreeCtrl ();

	// Get handle of selected item.  (Handle will be NULL if no item 
	// is selected.  We shouldn't get called if that is the case.)
	HTREEITEM hItem = cTree.GetSelectedItem ();
	
	if (hItem)
		{
		// Get pointer to our document:
		CKDocument *pDoc = (CKDocument *) GetDocument ();
	
		if (pDoc)
			{
			// Note: pointer to CKServer or CKGroup object is saved in
			// assoicated tree item's item data parameter.

			// If handle to parent item is NULL, we know a server was selected:
			if (cTree.GetParentItem (hItem) == NULL)
				pDoc->EditServer ((CKServer *) cTree.GetItemData (hItem));

			// Else a group must have been selected:
			else
				pDoc->EditGroup ((CKGroup *) cTree.GetItemData (hItem));
			}
		}
	}

// **************************************************************************
// OnCopy ()
//
// Description:
//	Copy menu event handler.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKGroupView::OnCopy () 
	{
	// Get reference to our tree control:
	CTreeCtrl &cTree = GetTreeCtrl ();

	// Get handle of selected item:
	HTREEITEM hItem = cTree.GetSelectedItem ();
		
	// Create a fixed shared memory file to copy data to:
	CFixedSharedFile sf;

	// Create a wait cursor object.  This will cause the wait cursor, 
	// usually an hourglass, to be displayed.  When this object goes
	// out of scope, its destructor will restore the previous cursor
	// type.
	CWaitCursor wc;

	// Create some scratch pointers:
	CKServer *pServer = NULL;
	CKGroup *pGroup = NULL;
	

	// Get the object and perform the copy:
	try
		{
		// If handle to parent item is NULL, we know a server is selected:
		if (cTree.GetParentItem (hItem) == NULL)
			{
			// Pointer to CKServer object is stored in tree item's item data parameter:
			pServer = (CKServer *) cTree.GetItemData (hItem);
			ASSERT (pServer != NULL);

			// Call server's copy function to place its properties in shared mem file:
			pServer->Copy (sf);
			}

		// Else a group must be selected:
		else
			{
			// Pointer to CKGroup object is stored in tree item's item data parameter:
			pGroup = (CKGroup *) cTree.GetItemData (hItem);
			ASSERT (pGroup != NULL);

			// Call group's copy functin to place its properties in shared mem file:
			pGroup->Copy (sf);
			}
		}

	catch (...)
		{
		ASSERT (FALSE);
		return;
		}

	// Copy the object data, contained in shared mem file, to clipboard:
	sf.CopyToClipboard (pServer != NULL ? CF_SERVER : CF_GROUP);
	}

// **************************************************************************
// OnCut ()
//
// Description:
//	Cut menu event handler.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKGroupView::OnCut () 
	{
	// Perform a copy first,
	OnCopy ();

	// then a delete:
	OnDelete ();
	}

// **************************************************************************
// OnPaste ()
//
// Description:
//	Paste menu event handler.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKGroupView::OnPaste () 
	{
	// Open the clipboard.  Proceed if succesful:
	if (OpenClipboard ())
		{
		// Get reference to our tree control:
		CTreeCtrl &cTree = GetTreeCtrl ();

		// Get handle of selected item:
		HTREEITEM hItem = cTree.GetSelectedItem ();

		// Get pointer to our document object:
		CKDocument *pDoc = (CKDocument *) GetDocument ();

		// Create a fixed shared memory file to copy clipboard data to:
		CFixedSharedFile sf;

		// Create a wait cursor object.  This will cause the wait cursor, 
		// usually an hourglass, to be displayed.  When this object goes
		// out of scope, its destructor will restore the previous cursor
		// type.
		CWaitCursor wc;

		try
			{
			// If server in the clipboard:
			if (IsClipboardFormatAvailable (CF_SERVER))
				{
				// Instantiate a new server object:
				CKServer *pServer = new CKServer;

				// Set shared memory file handle to clipboard data so we
				// can extract clipboard data using the memory file:
				sf.SetHandle (GetClipboardData (CF_SERVER), FALSE);

				// Call the server's paste function to load settings from
				// clipboard:
				pServer->Paste (sf);

				// Add server to project and connect:
				pDoc->AddServer (pServer, true /* connect */);
				}

			// Else if group is in the clipboard
			else if (IsClipboardFormatAvailable (CF_GROUP))
				{
				// We must be pasting to a server connection:
				ASSERT (cTree.GetParentItem (hItem) == NULL);
				
				// Instantiate a new group object, give it pointer to its
				// parent server object:
				CKGroup *pGroup = new CKGroup ((CKServer *) cTree.GetItemData (hItem));
				
				// Set shared memory file handle to clipboard data so we
				// can extract clipboard data using the memory file:
				sf.SetHandle (GetClipboardData (CF_GROUP), FALSE);

				// Call group's paste function to load settings from 
				// clipboard:
				pGroup->Paste (sf);

				// Add group to project:
				pDoc->AddGroup (pGroup);
				}

			// Else if item(s) are in the clipboard:
			else if (IsClipboardFormatAvailable (CF_ITEM))
				{
				// Create an object array to contain a list of items to be
				// added to a group:
				CObArray cItemList;
				DWORD cdwItems;
				CKItem *pItem;

				// Get pointer to group:
				CKGroup *pGroup = (CKGroup *) cTree.GetItemData (hItem);
				ASSERT (pGroup != NULL);

				// Set shared memory file handle to clipboard data so we
				// can extract clipboard data using the memory file:
				sf.SetHandle (GetClipboardData (CF_ITEM), FALSE);

				// Retrieve number of items:
				sf.Read (&cdwItems, sizeof (cdwItems));
				ASSERT (cdwItems > 0);

				// Allocate memory for items:
				cItemList.SetSize (cdwItems + 1);

				// Now retrieve the items:
				for (DWORD dwIndex = 0; dwIndex < cdwItems; dwIndex++)
					{
					// Instantiate a new item object:
					pItem = new CKItem (pGroup);

					// Call the item's paste function to load settings from 
					// clipboard:
					pItem->Paste (sf);

					// Add the item to object array:
					cItemList [dwIndex] = pItem;
					}

				// Terminate the list.  Will allow us to process list using
				// "while (element)" loop if we want:
				cItemList [dwIndex] = NULL;

				// Add the items:
				pDoc->AddItems (cItemList, cdwItems);
				}

			// Unidentified clipboard contents.  Throw exception.
			else
				throw (-1);
			}

		// If problem, empty clipboard contents:
		catch (...)
			{
			ASSERT (FALSE);
			EmptyClipboard (); 
			}

		// Free the shared memory handle:
		sf.Detach ();

		//  Close the clipboard:
		CloseClipboard ();
		}
	}

// **************************************************************************
// OnDelete ()
//
// Description:
//	Delete menu event handler.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKGroupView::OnDelete () 
	{
	// Get reference to our tree control:
	CTreeCtrl &cTree = GetTreeCtrl ();

	// Get handle of selected item.  (Handle will be NULL if no item is
	// selected):
	HTREEITEM hItem = cTree.GetSelectedItem ();

	// If an item was slected, delete it:
	if (hItem)
		{
		// Create a wait cursor object.  This will cause the wait cursor, 
		// usually an hourglass, to be displayed.  When this object goes
		// out of scope, its destructor will restore the previous cursor
		// type.
		CWaitCursor wc;

		// Get pointer to our document.  (Pointer will be NULL if we did
		// not get properly attached to document).
		CKDocument *pDoc = (CKDocument *) GetDocument ();
	
		// Tell document to remove server or group as case may be:
		if (pDoc)
			{
			// If handle of parent item is NULL, we know a server is selected:
			if (cTree.GetParentItem (hItem) == NULL)
				pDoc->RemoveServer ((CKServer *) cTree.GetItemData (hItem));
			
			// Else a group must be selected:
			else
				pDoc->RemoveGroup ((CKGroup *) cTree.GetItemData (hItem));
			}
		}
	}

// **************************************************************************
// OnConnect ()
//
// Description:
//	Connect menu event handler.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKGroupView::OnConnect () 
	{
	// Get reference to our tree control:
	CTreeCtrl &cTree = GetTreeCtrl ();

	// Get handle of selected item.  Handle will be NULL if no item is
	// selected.  We should only get called if a server is selected.
	HTREEITEM hItem = cTree.GetSelectedItem ();

	if (hItem)
		{
		// A server had better be selected.  This will be the case if handle
		// of parent is NULL.  Check this (debug only).
		ASSERT (cTree.GetParentItem (hItem) == NULL);

		// Get pointer to our document object.  (This could be NULL if
		// we did not get attached to document properly.)
		CKDocument *pDoc = (CKDocument *) GetDocument ();
		
		// Tell document to connect server.  Pointer to CKServer object is
		// saved in tree item data parameter.
		if (pDoc)
			pDoc->ConnectServer ((CKServer *) cTree.GetItemData (hItem));
		}
	}

// **************************************************************************
// OnDisconnect ()
//
// Description:
//	Disconnect menu event handler.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKGroupView::OnDisconnect () 
	{
	// Get reference to our tree control:
	CTreeCtrl &cTree = GetTreeCtrl ();

	// Get handle of selected item.  Handle will be NULL if no item is 
	// selected.  We should only get called if a server is selected.
	HTREEITEM hItem = cTree.GetSelectedItem ();

	if (hItem)
		{
		// A server had better be selected.  This will be the case if handle
		// of parent is NULL.  Check this (debug only).
		ASSERT (cTree.GetParentItem (hItem) == NULL);

		// Get pointer to our document object.  (This could be NULL if
		// we did not get attached to document properly.)
		CKDocument *pDoc = (CKDocument *) GetDocument ();
		
		// Tell document to disconnect server.  Pointer to CKServer object
		// is saved in tree item data parameter.
		if (pDoc)
			pDoc->DisconnectServer ((CKServer *) cTree.GetItemData (hItem));
		}
	}

// **************************************************************************
// OnReconnect ()
//
// Description:
//	Reconnect menu event handler.
//
// Parameters:

⌨️ 快捷键说明

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