Copying Data to the Clipboard Having registered a Clipboard format, we can look at copying data to the Clipboard. Let's first look at the OnUpdate. . . handler for the Edit Copy command: void CClipView::OnUpdateEditCopy(CCmdUI* pCmdUI) { int i = m_wndList.GetSelCount(); pCmdUI->Enable(i > 0 ? TRUE : FALSE); } If no items are selected, the command is disabled. This does two things: It shows the user the command won't do anything (it's grayed out), and it prevents us from getting Copy commands when there is nothing to copy. Let's look at the code for doing the actual copy operation: void CClipView::OnEditCopy() { // Get the number of selected items. int iCount = m_wndList.GetSelCount(); ASSERT(iCount > 0); // Get the list of selection IDs. int* pItems = new int [iCount]; m_wndList.GetSelItems(iCount, pItems); // Create a list. CMyObList ObList; // Add all the items to the list. int i; CMyObj* pObj; for (i=0; i The number of selected items is used to create a temporary array of selection IDs. The IDs are set into the array by calling GetSelItems. A new CMyObList is created and the pointer to each object is added to the list. Note that we are adding a reference to an object that is in use elsewhere, so it's important that we don't delete these objects by mistake when we're done here. Once the new CMyObList object has been built, a CSharedFile is created and an archive is created on top of the shared file. We can now serialize the list to the archive and, hence, to the shared file in memory. Once that's done, the memory of the shared file is detached, ready for sending to the Clipboard. The temporary CMyList object has all its items removed, not destroyed. The list object itself is, of course, destroyed when the function exits. The Clipboard is opened,