home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / OLEMETA.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  17.3 KB  |  682 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Implementation of TOleMetaPict, manipulates Ole2 MetafilePict/Icon
  6. //----------------------------------------------------------------------------
  7. #define INC_OLE2
  8. #include <owl/owlpch.h>
  9. #include <owl/oledlg.h>
  10.  
  11. //
  12. // OWL OLE Dialog diagnostic group.
  13. //
  14. DIAG_DECLARE_GROUP(OwlOleDlg);
  15.  
  16. //
  17. // Class used for label and source extraction from a metafile
  18. //
  19. class _OWLCLASS TLabelExtract {
  20.   public:
  21.     //
  22.     // Use memset to initialize PODS
  23.     //
  24.     TLabelExtract() {memset(this, 0, sizeof(TLabelExtract));}
  25.  
  26.     LPSTR       lpsz;
  27.     UINT        Index;      // index in lpsz (so we can retrieve 2+ lines)
  28.     DWORD       PrevIndex;  // index of last line (so we can mimic word wrap)
  29.  
  30.     union {
  31.       UINT      cch;        //Length of label for label extraction
  32.       UINT      iIcon;      //Index of icon in source extraction.
  33.     } u;
  34.  
  35.     //
  36.     //For internal use in enum procs
  37.     //
  38.     BOOL        fFoundIconOnly;
  39.     BOOL        fFoundSource;
  40.     BOOL        fFoundIndex;
  41. };
  42.  
  43. //
  44. // Class used for extracting icons from a metafile (CreateIcon parameters)
  45. //
  46. class _OWLCLASS TIconExtract {
  47.   public:
  48.     //
  49.     // Use memset to initialize PODS
  50.     //
  51.     TIconExtract() {memset(this, 0, sizeof(TIconExtract));}
  52.  
  53.     HICON       hIcon;          // Icon created in the enumeration proc.
  54.     BOOL        fAND;
  55.     HGLOBAL     hMemAND;        // Enumeration proc allocates and copies
  56.     HINSTANCE   hInst;          // Module instance handle
  57. };
  58.  
  59. //
  60. // Class used to pass info to EnumMetafileDraw
  61. //
  62. class _OWLCLASS TDrawInfo {
  63.   public:
  64.     //
  65.     // Use memset to initialize PODS
  66.     //
  67.     TDrawInfo() {memset(this, 0, sizeof(TDrawInfo));}
  68.  
  69.     RECT     Rect;
  70.     BOOL     fIconOnly;
  71. };
  72.  
  73. //
  74. // String [comment] in Metafile which flags that the label follows
  75. //
  76. static char szIconOnly[] = "IconOnly";       
  77.  
  78. int CALLBACK __export EnumMetafileIconDraw(HDC, HANDLETABLE FAR*, METARECORD FAR*, int, LPARAM);
  79. int CALLBACK __export EnumMetafileExtractLabel(HDC, HANDLETABLE FAR*, METARECORD FAR*, int, TLabelExtract far*);
  80. int CALLBACK __export EnumMetafileExtractIcon(HDC, HANDLETABLE FAR*, METARECORD FAR*, int, TIconExtract far*);
  81. int CALLBACK __export EnumMetafileExtractIconSource(HDC, HANDLETABLE FAR*, METARECORD FAR*, int, TLabelExtract far*);
  82.  
  83. //
  84. //
  85. //
  86. static uint
  87. MapLogHimToPix(int hiMetric, int pelsPerInch)
  88. {
  89.   return (uint)(((double)hiMetric * pelsPerInch)/HiMetricPerInch);
  90. }
  91.  
  92. //
  93. //
  94. //
  95. static int
  96. XformWidthInHimetricToPixels(TDC& dc, int widthInHiMetric)
  97. {
  98.   int logPix   = dc.GetDeviceCaps(LOGPIXELSX);
  99.   int pixWidth = MapLogHimToPix(widthInHiMetric, logPix);
  100.   return pixWidth;
  101. }
  102.  
  103. //
  104. //
  105. //
  106. static int
  107. XformHeightInHimetricToPixels(TDC& dc, int heightInHiMetric)
  108. {
  109.   int logPix    = dc.GetDeviceCaps(LOGPIXELSY);
  110.   int pixHeight = MapLogHimToPix(heightInHiMetric, logPix);
  111.   return pixHeight;
  112. }
  113.  
  114. //
  115. //
  116. //
  117. BOOL 
  118. OleUIMetafilePictIconDraw(HDC hDC, LPRECT pRect, 
  119.                           HGLOBAL hMetaPict, BOOL fIconOnly)
  120. {
  121.   LPMETAFILEPICT  pMF;
  122.   TDrawInfo        di;
  123.   int             cx, cy;
  124.   SIZE            size;
  125.   POINT           point;
  126.  
  127.   if (!hMetaPict)
  128.     return FALSE;
  129.  
  130.   pMF = (LPMETAFILEPICT)GlobalLock(hMetaPict);
  131.  
  132.   if (NULL==pMF) {
  133.     TRACEX(OwlOleDlg, 1, "Unable to lock MetaPict Handle");
  134.     return FALSE;
  135.   }
  136.  
  137.   di.Rect = *pRect;
  138.   di.fIconOnly = fIconOnly;
  139.  
  140.   //
  141.   // Transform to back to pixels
  142.   //
  143.   cx = XformWidthInHimetricToPixels(TDC(hDC), pMF->xExt);
  144.   cy = XformHeightInHimetricToPixels(TDC(hDC), pMF->yExt);
  145.  
  146.   SaveDC(hDC);
  147.  
  148.   SetMapMode(hDC, pMF->mm);
  149.   SetViewportOrgEx(hDC, (pRect->right - cx) / 2, 0, &point);
  150.  
  151.   SetViewportExtEx(hDC, min ((pRect->right - cx) / 2 + cx, cx), cy, &size);
  152.  
  153.   if (fIconOnly) {
  154.     EnumMetaFile(hDC, pMF->hMF, (MFENUMPROC)EnumMetafileIconDraw, 
  155.                 (LPARAM)(TDrawInfo far*)&di);
  156.   }
  157.   else {
  158.     PlayMetaFile(hDC, pMF->hMF);
  159.   }
  160.  
  161.   RestoreDC(hDC, -1);
  162.   GlobalUnlock(hMetaPict);
  163.   return TRUE;
  164. }
  165.  
  166. int CALLBACK __export
  167. EnumMetafileIconDraw(HDC hDC, HANDLETABLE FAR *phTable, 
  168.                      METARECORD FAR *pMFR, 
  169.                      int cObj, LPARAM lParam)
  170. {
  171.   TDrawInfo far* lpdi = (TDrawInfo far*)lParam;
  172.  
  173.   //
  174.   // We play everything blindly except for DIBBITBLT (or DIBSTRETCHBLT)
  175.   // and ESCAPE with MFCOMMENT.  For the BitBlts we change the x,y to
  176.   // draw at (0,0) instead of wherever it was written to draw.  The
  177.   // comment tells us there to stop if we don't want to draw the label.
  178.   //
  179.  
  180.   //
  181.   //If we're playing icon only, stop enumeration at the comment.
  182.   //
  183.   if (lpdi->fIconOnly) {
  184.     if (META_ESCAPE==pMFR->rdFunction && MFCOMMENT==pMFR->rdParm[0]) {
  185.       if (0==lstrcmpi(szIconOnly, (LPSTR)&pMFR->rdParm[2]))
  186.         return 0;
  187.     }
  188.  
  189.     //
  190.     // Check for the records in which we want to munge the coordinates.
  191.     // destX is offset 6 for BitBlt, offset 9 for StretchBlt, either of
  192.     // which may appear in the metafile.
  193.     // 
  194.     if (META_DIBBITBLT==pMFR->rdFunction)
  195.       pMFR->rdParm[6]=0;
  196.  
  197.     if (META_DIBSTRETCHBLT==pMFR->rdFunction)
  198.         pMFR->rdParm[9] = 0;
  199.   }
  200.  
  201.   PlayMetaFileRecord(hDC, phTable, pMFR, cObj);
  202.   return 1;
  203. }
  204.  
  205. UINT
  206. OleUIMetafilePictExtractLabel(HGLOBAL hMetaPict, LPSTR lpszLabel,
  207.                               UINT cchLabel, LPDWORD lpWrapIndex)
  208. {
  209.   LPMETAFILEPICT  pMF;
  210.   TLabelExtract    le;
  211.   HDC             hDC;
  212.  
  213.   //
  214.   // We extract the label by getting a screen DC and walking the metafile
  215.   // records until we see the ExtTextOut record we put there.  That
  216.   // record will have the string embedded in it which we then copy out.
  217.   //
  218.   if (!hMetaPict || !lpszLabel || !cchLabel)
  219.     return FALSE;
  220.  
  221.   pMF= (LPMETAFILEPICT)GlobalLock(hMetaPict);
  222.  
  223.   if (NULL==pMF)
  224.     return FALSE;
  225.  
  226.   le.lpsz=lpszLabel;
  227.   le.u.cch=cchLabel;
  228.   le.Index=0;
  229.   le.fFoundIconOnly=FALSE;
  230.   le.fFoundSource=FALSE;
  231.   le.fFoundIndex=FALSE;
  232.   le.PrevIndex = 0;
  233.  
  234.   //
  235.   // Use a screen DC so we have something valid to pass in.
  236.   //
  237.   hDC=GetDC(NULL);
  238.   EnumMetaFile(hDC, pMF->hMF, (MFENUMPROC)EnumMetafileExtractLabel,
  239.               (LONG)(TLabelExtract far*)&le);
  240.   ReleaseDC(NULL, hDC);
  241.  
  242.   GlobalUnlock(hMetaPict);
  243.  
  244.   //
  245.   // Tell where we wrapped (if calling function cares)
  246.   //
  247.   if (lpWrapIndex)
  248.     *lpWrapIndex = le.PrevIndex;
  249.  
  250.   //
  251.   // Return amount of text copied
  252.   //
  253.   return le.u.cch;
  254. }
  255.  
  256. int CALLBACK __export
  257. EnumMetafileExtractLabel(HDC /*hDC*/,
  258.                          HANDLETABLE FAR* /*phTable*/,
  259.                          METARECORD FAR *pMFR,
  260.                          int /*cObj*/, 
  261.                          TLabelExtract far* pLE)
  262. {
  263.   //
  264.   // We don't allow anything to happen until we see "IconOnly"
  265.   // in an MFCOMMENT that is used to enable everything else.
  266.   // 
  267.   if (!pLE->fFoundIconOnly) {
  268.     if (META_ESCAPE==pMFR->rdFunction && MFCOMMENT==pMFR->rdParm[0]) {
  269.       if (0==lstrcmpi(szIconOnly, (LPSTR)&pMFR->rdParm[2]))
  270.         pLE->fFoundIconOnly=TRUE;
  271.     }
  272.  
  273.     return 1;
  274.   }
  275.  
  276.   //
  277.   // Enumerate all records looking for META_EXTTEXTOUT - there can be more
  278.   // than one.
  279.   //
  280.   if (META_EXTTEXTOUT==pMFR->rdFunction) {
  281.     UINT        cchMax;
  282.     LPSTR       lpszTemp;
  283.  
  284.     //
  285.     // If ExtTextOut has NULL fuOptions, then the rectangle is omitted
  286.     // from the record, and the string starts at rdParm[4].  If
  287.     // fuOptions is non-NULL, then the string starts at rdParm[8]
  288.     // (since the rectange takes up four WORDs in the array).  In
  289.     // both cases, the string continues for (rdParm[2]+1) >> 1
  290.     // words.  We just cast a pointer to rdParm[8] to an LPSTR and
  291.     // lstrcpyn into the buffer we were given.
  292.     //
  293.     // Note that we use element 8 in rdParm instead of 4 because we
  294.     // passed ETO_CLIPPED in for the options on ExtTextOut--docs say
  295.     // [4] which is rect doesn't exist if we passed zero there.
  296.     //
  297.     // 
  298.     cchMax=min(pLE->u.cch - pLE->Index, (UINT)pMFR->rdParm[2]);
  299.     lpszTemp = pLE->lpsz + pLE->Index;
  300.  
  301.     lstrcpyn(lpszTemp, (LPSTR)&(pMFR->rdParm[8]), cchMax + 1);
  302.  
  303.     pLE->PrevIndex = pLE->Index;
  304.     pLE->Index += cchMax;
  305.   }
  306.  
  307.   return 1;
  308. }
  309.  
  310. HICON 
  311. OleUIMetafilePictExtractIcon(HGLOBAL hMetaPict, HINSTANCE hinst)
  312. {
  313.   LPMETAFILEPICT  pMF;
  314.   HDC             hDC;
  315.   TIconExtract     ie;
  316.  
  317.   //
  318.   // We extract the label by getting a screen DC and walking the metafile
  319.   // records until we see the ExtTextOut record we put there.  That
  320.   // record will have the string embedded in it which we then copy out.
  321.   // 
  322.  
  323.   if (NULL==hMetaPict)
  324.     return NULL;
  325.  
  326.   pMF= (LPMETAFILEPICT)GlobalLock(hMetaPict);
  327.  
  328.   if (NULL==pMF)
  329.     return FALSE;
  330.  
  331.   ie.fAND=TRUE;
  332.   ie.hInst = hinst;
  333.  
  334.   hDC=GetDC(NULL);
  335.   EnumMetaFile(hDC, pMF->hMF, (MFENUMPROC)EnumMetafileExtractIcon, 
  336.               (LONG)(TIconExtract far*)&ie);
  337.   ReleaseDC(NULL, hDC);
  338.   GlobalUnlock(hMetaPict);
  339.  
  340.   return ie.hIcon;
  341. }
  342.  
  343. int CALLBACK __export
  344. EnumMetafileExtractIcon(HDC hDC, HANDLETABLE FAR* /*phTable*/,
  345.                         METARECORD FAR *pMFR, int /*cObj*/,
  346.                         TIconExtract far* pIE)
  347. {
  348.   LPBITMAPINFO        lpBI;
  349.   LPBITMAPINFOHEADER  lpBH;
  350.   LPBYTE              lpbSrc;
  351.   LPBYTE              lpbDst;
  352.   UINT                uWidth, uHeight;
  353.   DWORD               cb;
  354.   HGLOBAL             hMem;
  355.   BITMAP              bm;
  356.   HBITMAP             hBmp;
  357.  
  358.   //
  359.   // Continue enumeration if we don't see the records we want.
  360.   //
  361.   if (META_DIBBITBLT != pMFR->rdFunction && 
  362.       META_DIBSTRETCHBLT != pMFR->rdFunction)
  363.     return 1;
  364.  
  365.   //
  366.   // Windows 3.0 DrawIcon uses META_DIBBITBLT in whereas 3.1 uses
  367.   // META_DIBSTRETCHBLT so we have to handle each case separately.
  368.   // 
  369.  
  370.   if (META_DIBBITBLT==pMFR->rdFunction) {
  371.     //
  372.     // Get dimensions and the BITMAPINFO struct.
  373.     //
  374.     uHeight=pMFR->rdParm[1];
  375.     uWidth =pMFR->rdParm[2];
  376.     lpBI=(LPBITMAPINFO)&(pMFR->rdParm[8]);
  377.   }
  378.   if (META_DIBSTRETCHBLT==pMFR->rdFunction) {
  379.     //
  380.     // Get dimensions and the BITMAPINFO struct.
  381.     //
  382.     uHeight=pMFR->rdParm[2];
  383.     uWidth =pMFR->rdParm[3];
  384.     lpBI=(LPBITMAPINFO)&(pMFR->rdParm[10]);
  385.   }
  386.  
  387.   lpBH=(LPBITMAPINFOHEADER)&(lpBI->bmiHeader);
  388.  
  389.   //
  390.   // Pointer to the bits which follows the BITMAPINFO structure.
  391.   //
  392.   lpbSrc=(LPBYTE)lpBI+sizeof(BITMAPINFOHEADER);
  393.  
  394.   //
  395.   // Add the length of the color table.
  396.   //
  397.   if (0!=lpBH->biClrUsed)
  398.     lpbSrc+=(int)(DWORD)(lpBH->biClrUsed*sizeof(RGBQUAD));
  399.   else  {
  400.     //
  401.     // 1 << bc gives 2, 16, 256 for 1, 4, or 256 colors
  402.     lpbSrc+=(int)(DWORD)((1 << (lpBH->biBitCount))*sizeof(RGBQUAD));
  403.   }
  404.  
  405.   //
  406.   // All the bits we have in lpbSrc are device-independent, so we
  407.   // need to change them over to be device-dependent using SetDIBits.
  408.   // Once we have a bitmap with the device-dependent bits, we can
  409.   // GetBitmapBits to have buffers with the real data.
  410.   //
  411.   // For each pass we have to allocate memory for the bits.  We save
  412.   // the memory for the mask between passes.
  413.   // 
  414.      
  415.   //
  416.   // Use CreateBitmap for ANY monochrome bitmaps
  417.   //
  418.   if (pIE->fAND || 1==lpBH->biBitCount || lpBH->biBitCount > 8)
  419.     hBmp=CreateBitmap((UINT)lpBH->biWidth, (UINT)lpBH->biHeight, 1, 1, NULL);
  420.   else if (lpBH->biBitCount <= 8)
  421.     hBmp=CreateCompatibleBitmap(hDC, (UINT)lpBH->biWidth, (UINT)lpBH->biHeight);
  422.  
  423.   if (!hBmp || !SetDIBits(hDC, hBmp, 0, (UINT)lpBH->biHeight, 
  424.                          (LPVOID)lpbSrc, lpBI, DIB_RGB_COLORS)) {
  425.     if (!pIE->fAND)
  426.       GlobalFree(pIE->hMemAND);
  427.  
  428.     DeleteObject(hBmp);
  429.     return 0;
  430.   }
  431.  
  432.   //
  433.   // Allocate memory and get the DDBits into it.
  434.   //
  435.   GetObject(hBmp, sizeof(bm), &bm);
  436.  
  437.   cb=bm.bmHeight*bm.bmWidthBytes * bm.bmPlanes;
  438.  
  439.   hMem=GlobalAlloc(GHND, cb);
  440.  
  441.   if (NULL==hMem) {
  442.     if (NULL!=pIE->hMemAND)
  443.       GlobalFree(pIE->hMemAND);
  444.  
  445.     DeleteObject(hBmp);
  446.     return 0;
  447.   }
  448.  
  449.   lpbDst=(LPBYTE)GlobalLock(hMem);
  450.   GetBitmapBits(hBmp, cb, (LPVOID)lpbDst);
  451.  
  452.   DeleteObject(hBmp);
  453.   GlobalUnlock(hMem);
  454.  
  455.   //
  456.   // If this is the first pass (pIE->fAND==TRUE) then save the memory
  457.   // of the AND bits for the next pass.
  458.   // 
  459.   if (pIE->fAND) {
  460.     pIE->fAND=FALSE;
  461.     pIE->hMemAND=hMem;
  462.  
  463.     //
  464.     // Continue enumeration looking for the next blt record.
  465.     //
  466.     return 1;
  467.   }
  468.   else {
  469.     //
  470.     // Get the AND pointer again.
  471.     //
  472.     lpbSrc=(LPBYTE)GlobalLock(pIE->hMemAND);
  473.  
  474.     //
  475.     // Create the icon now that we have all the data.  lpbDst already
  476.     // points to the XOR bits.
  477.     // 
  478.     pIE->hIcon=CreateIcon(pIE->hInst, uWidth, uHeight, (BYTE)bm.bmPlanes,
  479.                          (BYTE)bm.bmBitsPixel, (LPVOID)lpbSrc,
  480.                          (LPVOID)lpbDst);
  481.  
  482.     GlobalUnlock(pIE->hMemAND);
  483.     GlobalFree(pIE->hMemAND);
  484.     GlobalFree(hMem);
  485.  
  486.     //
  487.     // We're done so we can stop.
  488.     //
  489.     return 0;
  490.   }
  491. }
  492.  
  493. BOOL OleUIMetafilePictExtractIconSource(HGLOBAL hMetaPict, 
  494.                                         LPSTR lpszSource, 
  495.                                         UINT FAR *piIcon)
  496. {
  497.   LPMETAFILEPICT  pMF;
  498.   TLabelExtract    le;
  499.   HDC             hDC;
  500.  
  501.   //
  502.   // We will walk the metafile looking for the two comment records
  503.   // following the IconOnly comment.  The flags fFoundIconOnly and
  504.   // fFoundSource indicate if we have found IconOnly and if we have
  505.   // found the source comment already.
  506.   // 
  507.   if (NULL==hMetaPict || NULL==lpszSource || NULL==piIcon)
  508.     return FALSE;
  509.  
  510.   pMF=(LPMETAFILEPICT)GlobalLock(hMetaPict);
  511.  
  512.   if (NULL==pMF)
  513.     return FALSE;
  514.  
  515.   le.lpsz=lpszSource;
  516.   le.fFoundIconOnly=FALSE;
  517.   le.fFoundSource=FALSE;
  518.   le.fFoundIndex=FALSE;
  519.  
  520.   //
  521.   // Use a screen DC so we have something valid to pass in.
  522.   //
  523.   hDC=GetDC(NULL);
  524.   EnumMetaFile(hDC, pMF->hMF, (MFENUMPROC)EnumMetafileExtractIconSource, 
  525.               (LONG)(TLabelExtract far*)&le);
  526.   ReleaseDC(NULL, hDC);
  527.  
  528.   GlobalUnlock(hMetaPict);
  529.  
  530.   //
  531.   // Copy the icon index to the caller's variable.
  532.   //
  533.   *piIcon=le.u.iIcon;
  534.   
  535.   //
  536.   // Check that we found everything.
  537.   //
  538.   return (le.fFoundIconOnly && le.fFoundSource && le.fFoundIndex);
  539. }
  540.  
  541. int CALLBACK __export
  542. EnumMetafileExtractIconSource(HDC /*hDC*/,
  543.                               HANDLETABLE FAR* /*phTable*/,
  544.                               METARECORD FAR *pMFR,
  545.                               int /*cObj*/, 
  546.                               TLabelExtract far* pLE)
  547. {
  548.   LPSTR psz;
  549.  
  550.   //
  551.   // We don't allow anything to happen until we see "IconOnly"
  552.   // in an MFCOMMENT that is used to enable everything else.
  553.   // 
  554.   if (!pLE->fFoundIconOnly) {
  555.     if (META_ESCAPE==pMFR->rdFunction && MFCOMMENT==pMFR->rdParm[0]) {
  556.       if (0==lstrcmpi(szIconOnly, (LPSTR)&pMFR->rdParm[2]))
  557.         pLE->fFoundIconOnly=TRUE;
  558.       }
  559.  
  560.     return 1;
  561.   }
  562.  
  563.   //
  564.   // Now see if we find the source string.
  565.   //
  566.   if (!pLE->fFoundSource) {
  567.     if (META_ESCAPE==pMFR->rdFunction && MFCOMMENT==pMFR->rdParm[0]) {
  568.       strcpyn(pLE->lpsz, (LPSTR)&pMFR->rdParm[2], MaxPathLen);
  569.       pLE->lpsz[MaxPathLen-1] = '\0';
  570.       pLE->fFoundSource=TRUE;
  571.     }
  572.  
  573.     return 1;
  574.   }
  575.  
  576.   //
  577.   // Next comment will be the icon index.
  578.   //
  579.   if (META_ESCAPE==pMFR->rdFunction && MFCOMMENT==pMFR->rdParm[0]) {
  580.     //
  581.     // This string contains the icon index in string form,
  582.     // so we need to convert back to a UINT.  After we see this
  583.     // we can stop the enumeration.  The comment will have
  584.     // a null terminator because we made sure to save it.
  585.     //
  586.     psz=(LPSTR)&pMFR->rdParm[2];
  587.     pLE->u.iIcon=0;
  588.  
  589.     //
  590.     // Do Ye Olde atoi
  591.     //
  592.     while (*psz)
  593.       pLE->u.iIcon=(10*pLE->u.iIcon)+((*psz++)-'0');
  594.  
  595.     pLE->fFoundIndex=TRUE;
  596.     return 0;
  597.   }
  598.  
  599.   return 1;
  600. }
  601.  
  602. //
  603. // Aliases an OLE MetafilePictIcon
  604. //
  605. TOleMetaPict::TOleMetaPict(HGLOBAL metaPict, TAutoDelete autoDelete):
  606.               MetaPict(metaPict), ShouldDelete(autoDelete==AutoDelete)
  607. {}
  608.  
  609. //
  610. // Frees Metafile and Memory handle (if ShouldDelete)
  611. //
  612. TOleMetaPict::~TOleMetaPict()
  613. {
  614.   if (ShouldDelete)
  615.     Free(MetaPict);
  616. }
  617.  
  618. //
  619. // Frees the Metafile Handle and Global Memory Handle
  620. //
  621. bool
  622. TOleMetaPict::Free(HGLOBAL& metaPict)
  623. {
  624.   if (!metaPict)
  625.     return false;
  626.  
  627.   LPMETAFILEPICT pMF = (LPMETAFILEPICT)GlobalLock(metaPict);
  628.   if (!pMF) {
  629.     TRACEX(OwlOleDlg, 1, "Unable to lock MetaPict Handle");
  630.     return false;
  631.   }
  632.  
  633.   if (pMF->hMF)
  634.     DeleteMetaFile(pMF->hMF);
  635.  
  636.   GlobalUnlock(metaPict);
  637.   GlobalFree(metaPict);
  638.   metaPict = 0;
  639.   return true;
  640. }
  641.  
  642. //
  643. //
  644. //
  645. bool
  646. TOleMetaPict::Draw(TDC& dc, TRect& rect, bool iconOnly) const
  647. {
  648.   PRECONDITION(MetaPict);
  649.   return OleUIMetafilePictIconDraw(dc, &rect, MetaPict, iconOnly) ?
  650.          true : false;  
  651. }
  652.  
  653. //
  654. //
  655. //
  656. int
  657. TOleMetaPict::ExtractLabel(char far* label, uint32 *wrap) const
  658. {
  659.   PRECONDITION(MetaPict);
  660.   return OleUIMetafilePictExtractLabel(MetaPict, label, MaxLabelLen, wrap);
  661. }
  662.  
  663. //
  664. //
  665. //
  666. HICON
  667. TOleMetaPict::ExtractIcon(HINSTANCE hinst) const
  668. {
  669.   PRECONDITION(MetaPict);
  670.   return OleUIMetafilePictExtractIcon(MetaPict, hinst);
  671. }
  672.  
  673. //
  674. //
  675. //
  676. bool
  677. TOleMetaPict::ExtractIconSource(char far* source, uint& index) const
  678. {
  679.   PRECONDITION(MetaPict);
  680.   return OleUIMetafilePictExtractIconSource(MetaPict, source, &index);
  681. }
  682.