home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK11 / MFC / SAMPLES / TESTSERV / CLIPBD.CP$ / clipbd
Encoding:
Text File  |  1992-03-09  |  3.4 KB  |  144 lines

  1. // clipbd.cpp : This file contains code which implements functions
  2. //  specific to the clipboard.
  3. //
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and Microsoft
  10. // QuickHelp documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14.  
  15. #include "testserv.h"
  16.  
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19.  
  20. extern void OutputLog (const char* pText);
  21. extern UINT GLOBAL_uNativeFormat, GLOBAL_uOwnerFormat, GLOBAL_uObjectFormat;
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CTestServer::OnCopyLink()
  25. //
  26. void CTestServer::OnCopyLink()
  27. {
  28.     ASSERT_VALID(this);
  29.     if (!OpenClipboard())
  30.     {
  31.         MessageBox ("Unable to Open Clipboard", "Test Server",
  32.             MB_ICONEXCLAMATION);
  33.  
  34.         if (m_bLogging)
  35.         {
  36.             OutputLog("CTestServer::OnCopyLink : Unable to Open Clipboard\n");
  37.         }
  38.         return;
  39.     }
  40.  
  41.     EmptyClipboard();
  42.  
  43.     // copy the text into a memory block so it can be put on the
  44.     // clipboard.
  45.  
  46.     HANDLE hText;
  47.     CString stringText;
  48.     LPSTR lpTextLock;
  49.     
  50.     ASSERT(m_pItem != NULL);
  51.     m_pItem->OnGetTextData(stringText);
  52.     hText = ::GlobalAlloc (GMEM_DDESHARE | GHND, stringText.GetLength()+1);
  53.     lpTextLock = (LPSTR) ::GlobalLock(hText);
  54.  
  55.     for (int i=0; i<stringText.GetLength(); i++)
  56.     {
  57.         *lpTextLock++ = stringText[i];
  58.     }
  59.  
  60.     *lpTextLock++ = '\0';
  61.  
  62.     ::GlobalUnlock (hText);
  63.  
  64.     TRY
  65.     {
  66.         // Here we will set up the appropriate linking formats
  67.         SetClipboardData (CF_TEXT, hText);
  68.         SetClipboardData (CF_METAFILEPICT, m_pItem->GetMetafileData());
  69.         SetClipboardData (GLOBAL_uNativeFormat, m_pItem->GetNativeData());
  70.         SetClipboardData (GLOBAL_uOwnerFormat, m_pItem->GetLinkData());
  71.         SetClipboardData (GLOBAL_uObjectFormat, m_pItem->GetLinkData());
  72.     }
  73.     CATCH (COleException, e)
  74.     {
  75.         if (m_bLogging)
  76.         {
  77.             LogError(THIS_FILE, e->m_status);
  78.         }
  79.     }
  80.     END_CATCH
  81.     CloseClipboard();
  82. }
  83.  
  84.  
  85.  
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CTestServer::OnCopyObject()
  88. //
  89. void CTestServer::OnCopyObject()
  90. {
  91.     ASSERT_VALID(this);
  92.  
  93.     if (!OpenClipboard())
  94.     {
  95.         MessageBox ("Unable to Open Clipboard", "Test Server",
  96.             MB_ICONEXCLAMATION);
  97.         
  98.         if (m_bLogging)
  99.         {
  100.             OutputLog("CTestServer::OnCopyObject : Couldn't Open Clipboard\n");
  101.         }
  102.         return;
  103.     }
  104.  
  105.     EmptyClipboard();
  106.  
  107.     // Here we will set up the appropriate embedding formats
  108.     HANDLE hText;
  109.     CString stringText;
  110.     LPSTR lpTextLock;
  111.     
  112.     ASSERT(m_pItem != NULL);
  113.     m_pItem->OnGetTextData(stringText);
  114.     hText = ::GlobalAlloc (GMEM_DDESHARE | GHND, stringText.GetLength()+1);
  115.     lpTextLock = (LPSTR) ::GlobalLock(hText);
  116.  
  117.     for (int i=0; i<stringText.GetLength(); i++)
  118.     {
  119.         *lpTextLock++ = stringText[i];
  120.     }
  121.  
  122.     *lpTextLock++ = '\0';
  123.  
  124.     ::GlobalUnlock (hText);
  125.  
  126.     TRY
  127.     {
  128.         // Here we will set up the appropriate linking formats
  129.         SetClipboardData (CF_TEXT, hText);
  130.         SetClipboardData (CF_METAFILEPICT, m_pItem->GetMetafileData());
  131.         SetClipboardData (GLOBAL_uNativeFormat, m_pItem->GetNativeData());
  132.         SetClipboardData (GLOBAL_uOwnerFormat, m_pItem->GetLinkData());
  133.     }
  134.     CATCH (COleException, e)
  135.     {
  136.         if (m_bLogging)
  137.         {
  138.             LogError(THIS_FILE, e->m_status);
  139.         }
  140.     }
  141.     END_CATCH
  142.     CloseClipboard();
  143. }
  144.