home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap18 / cosmo1.0 / oleclip.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  3KB  |  149 lines

  1. /*
  2.  * OLECLIP.C
  3.  *
  4.  * Routines to handle placing Native, ObjectLink, and OwnerLink
  5.  * information on the clipboard.
  6.  *
  7.  * Copyright(c) Microsoft Corp. 1992-1994 All Rights Reserved
  8.  * Win32 version, January 1994
  9.  */
  10.  
  11.  
  12. #ifdef MAKEOLESERVER
  13.  
  14. #include <windows.h>
  15. #include <ole.h>
  16. #include "cosmo.h"
  17. #include "oleglobl.h"
  18.  
  19.  
  20.  
  21. /*
  22.  * FOLECopyNative
  23.  *
  24.  * Purpose:
  25.  *  Allocates a memory block for Native data and places it on the clipboard,
  26.  *  assuming that the application has opened the clipboard.
  27.  *
  28.  * Parameters:
  29.  *  pOLE            LPXOLEGLOBALS containing clipboard formats.
  30.  *
  31.  * Return Value:
  32.  *  BOOL            TRUE if the data was copied, FALSE otherwise.
  33.  */
  34.  
  35. BOOL WINAPI FOLECopyNative(LPXOLEGLOBALS pOLE)
  36.     {
  37.     HGLOBAL      hMem;
  38.  
  39.     hMem=HGetPolyline(pGlob->hWndPolyline);
  40.  
  41.     //Place Native data on clipboard.
  42.     if (NULL==hMem)
  43.         return FALSE;
  44.  
  45.     SetClipboardData(pOLE->cfNative, hMem);
  46.     return TRUE;
  47.     }
  48.  
  49.  
  50.  
  51.  
  52. /*
  53.  * FOLECopyLink
  54.  *
  55.  * Purpose:
  56.  *  Places ObjectLink OR OwnerLink information on the clipboard.
  57.  *  This function assumes that the application already has the
  58.  *  clipboard open.
  59.  *
  60.  * Parameters:
  61.  *  pOLE            LPXOLEGLOBALS containing clipboard formats.
  62.  *  fOwnerLink      BOOL indicating to set OwnerLink (TRUE)/ObjectLink (FALSE)
  63.  *  pszDoc          LPSTR to the document name.
  64.  *
  65.  * Return Value:
  66.  *  BOOL            TRUE if copying to the clipboard was successful.
  67.  *                  FALSE on any failure.
  68.  */
  69.  
  70. BOOL WINAPI FOLECopyLink(LPXOLEGLOBALS pOLE, BOOL fOwnerLink, LPSTR pszDoc)
  71.     {
  72.     HGLOBAL         hMem;
  73.     OLECLIPFORMAT   cf;
  74.  
  75.     //Retrieve a handle to the OwnerLink/ObjectLink format.
  76.     hMem=HLinkConstruct(rgpsz[IDS_CLASSCOSMO], pszDoc, rgpsz[IDS_FIGURE]);
  77.  
  78.     if (NULL==hMem)
  79.         return FALSE;
  80.  
  81.     //Set one or the other format.
  82.     cf=(fOwnerLink) ? (pOLE->cfOwnerLink) : (pOLE->cfObjectLink);
  83.     hMem=SetClipboardData(cf, hMem);
  84.  
  85.     return (NULL!=hMem);
  86.     }
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. /*
  94.  * HLinkConstruct
  95.  *
  96.  * Purpose:
  97.  *  Builds an ObjectLink and OwnerLink text string for OLE clipboard
  98.  *  interaction in the format of "classname\0document\0object\0\0"
  99.  *
  100.  * Parameters:
  101.  *  pszClass        LPSTR to the classname.
  102.  *  pszDoc          LPSTR to the document name.
  103.  *  pszObj          LPSTR to the object name.
  104.  *
  105.  * Return Value:
  106.  *  HGLOBAL         Global memory handle to an block containing
  107.  *                  the three strings with the appropriate separator.
  108.  */
  109.  
  110. HGLOBAL WINAPI HLinkConstruct(LPSTR pszClass, LPSTR pszDoc, LPSTR pszObj)
  111.     {
  112.     HGLOBAL     hMem;
  113.     UINT        cch1, cch2, cch3;
  114.     LPSTR       psz;
  115.  
  116.     if (NULL==pszClass || NULL==pszDoc || NULL==pszObj)
  117.         return NULL;
  118.  
  119.     //We'll need lengths later.
  120.     cch1=lstrlen(pszClass);
  121.     cch2=lstrlen(pszDoc);
  122.     cch3=lstrlen(pszObj);
  123.  
  124.     //Extra 4 is for the null-terminators.
  125.     hMem=GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, (DWORD)(4+cch1+cch2+cch3));
  126.  
  127.     if (NULL==hMem)
  128.         return NULL;
  129.  
  130.     psz=GlobalLock(hMem);
  131.  
  132.     lstrcpy(psz, pszClass);
  133.     psz+=cch1+1;
  134.  
  135.     lstrcpy(psz, pszDoc);
  136.     psz+=cch2+1;
  137.  
  138.     lstrcpy(psz, pszObj);
  139.     *(psz+cch3+1)=0;        //Add the final null terminator.
  140.  
  141.     GlobalUnlock(hMem);
  142.     return hMem;
  143.     }
  144.  
  145.  
  146.  
  147.  
  148. #endif //MAKEOLESERVER
  149.