home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / axpicker / clspnttl.cls < prev    next >
Encoding:
Visual Basic class definition  |  1998-10-22  |  42.6 KB  |  968 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "PaintEffects"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Attribute VB_Description = "Provides methods for painting transparent and disabled looking images."
  11. Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
  12. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  13.  
  14. '  MultiUse = -1  'True
  15. '  Persistable = 0  'NotPersistable
  16. '  DataBindingBehavior = 0  'vbNone
  17. '  DataSourceBehavior = 0   'vbNone
  18. '  MTSTransactionMode = 0   'NotAnMTSObject
  19. 'End
  20. Option Explicit
  21. ' ------------------------------------------------------------------------
  22. '      Copyright ⌐ 1997 Microsoft Corporation.  All rights reserved.
  23. '
  24. ' You have a royalty-free right to use, modify, reproduce and distribute
  25. ' the Sample Application Files (and/or any modified version) in any way
  26. ' you find useful, provided that you agree that Microsoft has no warranty,
  27. ' obligations or liability for any Sample Application Files.
  28. ' ------------------------------------------------------------------------
  29. '-------------------------------------------------------------------------
  30. 'This class provides methods needed for painting masked bitmaps and
  31. 'disabled or embossed bitmaps and icons
  32. '-------------------------------------------------------------------------
  33.  
  34. Private m_hpalHalftone As Long  'Halftone created for default palette use
  35.  
  36. '-------------------------------------------------------------------------
  37. 'Purpose:   Creates a disabled-appearing (grayed) bitmap, given any format of
  38. '           input bitmap.
  39. 'In:
  40. '   [hdcDest]
  41. '           Device context to paint the picture on
  42. '   [xDest]
  43. '           X coordinate of the upper left corner of the area that the
  44. '           picture is to be painted on. (in pixels)
  45. '   [yDest]
  46. '           Y coordinate of the upper left corner of the area that the
  47. '           picture is to be painted on. (in pixels)
  48. '   [Width]
  49. '           Width of picture area to paint in pixels.  Note: If this value
  50. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  51. '           instead of the pictures' width in pixels), this procedure will
  52. '           attempt to create bitmaps that require outrageous
  53. '           amounts of memory.
  54. '   [Height]
  55. '           Height of picture area to paint in pixels.  Note: If this
  56. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  57. '           twips instead of the pictures' height in pixels), this
  58. '           procedure will attempt to create bitmaps that require
  59. '           outrageous amounts of memory.
  60. '   [picSource]
  61. '           Standard Picture object to be used as the image source
  62. '   [xSrc]
  63. '           X coordinate of the upper left corner of the area in the picture
  64. '           to use as the source. (in pixels)
  65. '           Ignored if picSource is an Icon.
  66. '   [ySrc]
  67. '           Y coordinate of the upper left corner of the area in the picture
  68. '           to use as the source. (in pixels)
  69. '           Ignored if picSource is an Icon.
  70. '   [clrMask]
  71. '           Color of pixels to be masked out
  72. '   [clrHighlight]
  73. '           Color to be used as outline highlight
  74. '   [clrShadow]
  75. '           Color to be used as outline shadow
  76. '   [hPal]
  77. '           Handle of palette to select into the memory DC's used to create
  78. '           the painting effect.
  79. '           If not provided, a HalfTone palette is used.
  80. '-------------------------------------------------------------------------
  81. Public Sub PaintDisabledStdPic(ByVal hdcDest As Long, _
  82.                                 ByVal xDest As Long, _
  83.                                 ByVal yDest As Long, _
  84.                                 ByVal Width As Long, _
  85.                                 ByVal Height As Long, _
  86.                                 ByVal picSource As StdPicture, _
  87.                                 ByVal xSrc As Long, _
  88.                                 ByVal ySrc As Long, _
  89.                                 Optional ByVal clrMask As OLE_COLOR = vbWhite, _
  90.                                 Optional ByVal clrHighlight As OLE_COLOR = vb3DHighlight, _
  91.                                 Optional ByVal clrShadow As OLE_COLOR = vb3DShadow, _
  92.                                 Optional ByVal hPal As Long = 0)
  93. Attribute PaintDisabledStdPic.VB_Description = "Paints a disabled appearing image (embossed) given a source picture object."
  94.     Dim hDcSrc As Long         'HDC that the source bitmap is selected into
  95.     Dim hbmMemSrcOld As Long
  96.     Dim hbmMemSrc As Long
  97.     Dim udtRect As RECT
  98.     Dim hbrMask As Long
  99.     Dim lMaskColor As Long
  100.     Dim hDcScreen As Long
  101.     Dim hPalOld As Long
  102.     
  103.     'Verify that the passed picture is not nothing
  104.     If picSource Is Nothing Then GoTo PaintDisabledDC_InvalidParam
  105.     Select Case picSource.Type
  106.         Case vbPicTypeBitmap
  107.             'Select passed picture into an HDC
  108.             hDcScreen = GetDC(0&)
  109.             'Validate palette
  110.             If hPal = 0 Then
  111.                 hPal = m_hpalHalftone
  112.             End If
  113.             hDcSrc = CreateCompatibleDC(hDcScreen)
  114.             hbmMemSrcOld = SelectObject(hDcSrc, picSource.handle)
  115.             hPalOld = SelectPalette(hDcSrc, hPal, True)
  116.             RealizePalette hDcSrc
  117.             
  118.             'Draw the bitmap
  119.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hDcSrc, xSrc, ySrc, clrMask, clrHighlight, clrShadow, hPal
  120.             
  121.             SelectObject hDcSrc, hbmMemSrcOld
  122.             SelectPalette hDcSrc, hPalOld, True
  123.             RealizePalette hDcSrc
  124.             DeleteDC hDcSrc
  125.             ReleaseDC 0&, hDcScreen
  126.         Case vbPicTypeIcon
  127.             'Create a bitmap and select it into a DC
  128.             hDcScreen = GetDC(0&)
  129.             'Validate palette
  130.             If hPal = 0 Then
  131.                 hPal = m_hpalHalftone
  132.             End If
  133.             hDcSrc = CreateCompatibleDC(hDcScreen)
  134.             hbmMemSrc = CreateCompatibleBitmap(hDcScreen, Width, Height)
  135.             hbmMemSrcOld = SelectObject(hDcSrc, hbmMemSrc)
  136.             hPalOld = SelectPalette(hDcSrc, hPal, True)
  137.             RealizePalette hDcSrc
  138.             'Draw Icon onto DC
  139.             udtRect.Bottom = Height
  140.             udtRect.Right = Width
  141.             OleTranslateColor clrMask, 0&, lMaskColor
  142.             SetBkColor hDcSrc, lMaskColor
  143.             hbrMask = CreateSolidBrush(lMaskColor)
  144.             FillRect hDcSrc, udtRect, hbrMask
  145.             DeleteObject hbrMask
  146.             DrawIcon hDcSrc, 0, 0, picSource.handle
  147.             'Draw Disabled image
  148.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hDcSrc, 0&, 0&, clrMask, clrHighlight, clrShadow, hPal
  149.             'Clean up
  150.             SelectPalette hDcSrc, hPalOld, True
  151.             RealizePalette hDcSrc
  152.             DeleteObject SelectObject(hDcSrc, hbmMemSrcOld)
  153.             DeleteDC hDcSrc
  154.             ReleaseDC 0&, hDcScreen
  155.         Case Else
  156.             GoTo PaintDisabledDC_InvalidParam
  157.     End Select
  158.     Exit Sub
  159. PaintDisabledDC_InvalidParam:
  160.     'Error.Raise giINVALID_PICTURE
  161.     Exit Sub
  162. End Sub
  163.  
  164. '-------------------------------------------------------------------------
  165. 'Purpose:   Creates a disabled-appearing (grayed) bitmap, given any format of
  166. '           input bitmap.
  167. 'In:
  168. '   [hdcDest]
  169. '           Device context to paint the picture on
  170. '   [xDest]
  171. '           X coordinate of the upper left corner of the area that the
  172. '           picture is to be painted on. (in pixels)
  173. '   [yDest]
  174. '           Y coordinate of the upper left corner of the area that the
  175. '           picture is to be painted on. (in pixels)
  176. '   [Width]
  177. '           Width of picture area to paint in pixels.  Note: If this value
  178. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  179. '           instead of the pictures' width in pixels), this procedure will
  180. '           attempt to create bitmaps that require outrageous
  181. '           amounts of memory.
  182. '   [Height]
  183. '           Height of picture area to paint in pixels.  Note: If this
  184. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  185. '           twips instead of the pictures' height in pixels), this
  186. '           procedure will attempt to create bitmaps that require
  187. '           outrageous amounts of memory.
  188. '   [hdcSrc]
  189. '           Device context that contains the source picture
  190. '   [xSrc]
  191. '           X coordinate of the upper left corner of the area in the picture
  192. '           to use as the source. (in pixels)
  193. '   [ySrc]
  194. '           Y coordinate of the upper left corner of the area in the picture
  195. '           to use as the source. (in pixels)
  196. '   [clrMask]
  197. '           Color of pixels to be masked out
  198. '   [clrHighlight]
  199. '           Color to be used as outline highlight
  200. '   [clrShadow]
  201. '           Color to be used as outline shadow
  202. '   [hPal]
  203. '           Handle of palette to select into the memory DC's used to create
  204. '           the painting effect.
  205. '           If not provided, a HalfTone palette is used.
  206. '-------------------------------------------------------------------------
  207. Public Sub PaintDisabledDC(ByVal hdcDest As Long, _
  208.                                 ByVal xDest As Long, _
  209.                                 ByVal yDest As Long, _
  210.                                 ByVal Width As Long, _
  211.                                 ByVal Height As Long, _
  212.                                 ByVal hDcSrc As Long, _
  213.                                 ByVal xSrc As Long, _
  214.                                 ByVal ySrc As Long, _
  215.                                 Optional ByVal clrMask As OLE_COLOR = vbWhite, _
  216.                                 Optional ByVal clrHighlight As OLE_COLOR = vb3DHighlight, _
  217.                                 Optional ByVal clrShadow As OLE_COLOR = vb3DShadow, _
  218.                                 Optional ByVal hPal As Long = 0)
  219. Attribute PaintDisabledDC.VB_Description = "Paints a disabled appearing image (embossed) given a source hDC."
  220.     Dim hDcScreen As Long
  221.     Dim hbmMonoSection As Long
  222.     Dim hbmMonoSectionSav As Long
  223.     Dim hdcMonoSection As Long
  224.     Dim hdcColor As Long
  225.     Dim hdcDisabled As Long
  226.     Dim hbmDisabledSav As Long
  227.     Dim lpbi As BITMAPINFO
  228.     Dim hbmMono As Long
  229.     Dim hdcMono As Long
  230.     Dim hbmMonoSav As Long
  231.     Dim lMaskColor As Long
  232.     Dim lMaskColorCompare As Long
  233.     Dim hdcMaskedSource As Long
  234.     Dim hbmMasked As Long
  235.     Dim hbmMaskedOld As Long
  236.     Dim hpalMaskedOld As Long
  237.     Dim hpalDisabledOld As Long
  238.     Dim hpalMonoOld As Long
  239.     Dim rgbBlack As RGBQUAD
  240.     Dim rgbWhite As RGBQUAD
  241.     Dim dwSys3dShadow As Long
  242.     Dim dwSys3dHighlight As Long
  243.     Dim pvBits As Long
  244.     Dim rgbnew(1) As RGBQUAD
  245.     Dim hbmDisabled As Long
  246.     Dim lMonoBkGrnd As Long
  247.     Dim lMonoBkGrndChoices(2) As Long
  248.     Dim lIndex As Long  'For ... Next index
  249.     Dim hbrWhite As Long
  250.     Dim udtRect As RECT
  251.     
  252.     'TODO: handle pictures with dark masks
  253.     If hPal = 0 Then
  254.         hPal = m_hpalHalftone
  255.     End If
  256.   ' Define some colors
  257.     OleTranslateColor clrShadow, hPal, dwSys3dShadow
  258.     OleTranslateColor clrHighlight, hPal, dwSys3dHighlight
  259.     
  260.     hDcScreen = GetDC(0&)
  261.     With rgbBlack
  262.         .rgbBlue = 0
  263.         .rgbGreen = 0
  264.         .rgbRed = 0
  265.         .rgbReserved = 0
  266.     End With
  267.     With rgbWhite
  268.         .rgbBlue = 255
  269.         .rgbGreen = 255
  270.         .rgbRed = 255
  271.         .rgbReserved = 255
  272.     End With
  273.  
  274.     ' The first step is to create a monochrome bitmap with two colors:
  275.     ' white where colors in the original are light, and black
  276.     ' where the original is dark.  We can't simply bitblt to a bitmap.
  277.     ' Instead, we create a monochrome (bichrome?) DIB section and bitblt
  278.     ' to that.  Windows will do the conversion automatically based on the
  279.     ' DIB section's palette.  (I.e. using a DIB section, Windows knows how
  280.     ' to map "light" colors and "dark" colors to white/black, respectively.
  281.     With lpbi.bmiHeader
  282.         .biSize = LenB(lpbi.bmiHeader)
  283.         .biWidth = Width
  284.         .biHeight = -Height
  285.         .biPlanes = 1
  286.         .biBitCount = 1         ' monochrome
  287.         .biCompression = BI_RGB
  288.         .biSizeImage = 0
  289.         .biXPelsPerMeter = 0
  290.         .biYPelsPerMeter = 0
  291.         .biClrUsed = 0          ' max colors used (2^1 = 2)
  292.         .biClrImportant = 0     ' all (both :-]) colors are important
  293.     End With
  294.     With lpbi
  295.         .bmiColors(0) = rgbBlack
  296.         .bmiColors(1) = rgbWhite
  297.     End With
  298.  
  299.     hbmMonoSection = CreateDIBSection(hDcScreen, lpbi, DIB_RGB_COLORS, pvBits, 0&, 0)
  300.     
  301.     hdcMonoSection = CreateCompatibleDC(hDcScreen)
  302.     hbmMonoSectionSav = SelectObject(hdcMonoSection, hbmMonoSection)
  303.     
  304.     'Bitblt to the Monochrome DIB section
  305.     'If a mask color is provided, create a new bitmap and copy the source
  306.     'to it transparently.  If we don't do this, a dark mask color will be
  307.     'turned into the outline part of the monochrome DIB section
  308.     'Convert mask color and white before comparing
  309.     'because the Mask color might be a system color that would be evaluated
  310.     'to white.
  311.     OleTranslateColor vbWhite, hPal, lMaskColorCompare
  312.     OleTranslateColor clrMask, hPal, lMaskColor
  313.     If lMaskColor = lMaskColorCompare Then
  314.         BitBlt hdcMonoSection, 0, 0, Width, Height, hDcSrc, xSrc, ySrc, vbSrcCopy
  315.     Else
  316.         hbmMasked = CreateCompatibleBitmap(hDcScreen, Width, Height)
  317.         hdcMaskedSource = CreateCompatibleDC(hDcScreen)
  318.         hbmMaskedOld = SelectObject(hdcMaskedSource, hbmMasked)
  319.         hpalMaskedOld = SelectPalette(hdcMaskedSource, hPal, True)
  320.         RealizePalette hdcMaskedSource
  321.         'Fill the bitmap with white
  322.         With udtRect
  323.             .Left = 0
  324.             .Top = 0
  325.             .Right = Width
  326.             .Bottom = Height
  327.         End With
  328.         hbrWhite = CreateSolidBrush(vbWhite)
  329.         FillRect hdcMaskedSource, udtRect, hbrWhite
  330.         DeleteObject hbrWhite
  331.         'Do the transparent paint
  332.         PaintTransparentDC hdcMaskedSource, 0, 0, Width, Height, hDcSrc, xSrc, ySrc, lMaskColor, hPal
  333.         'BitBlt to the Mono DIB section.  The mask color has been turned to white.
  334.         BitBlt hdcMonoSection, 0, 0, Width, Height, hdcMaskedSource, 0, 0, vbSrcCopy
  335.         'Clean up
  336.         SelectPalette hdcMaskedSource, hpalMaskedOld, True
  337.         RealizePalette hdcMaskedSource
  338.         DeleteObject SelectObject(hdcMaskedSource, hbmMaskedOld)
  339.         DeleteDC hdcMaskedSource
  340.     End If
  341.       
  342.     ' Okay, we've got our B&W DIB section.
  343.     ' Now that we have our monochrome bitmap, the final appearance that we
  344.     ' want is this:  First, think of the black portion of the monochrome
  345.     ' bitmap as our new version of the original bitmap.  We want to have a dark
  346.     ' gray version of this with a light version underneath it, shifted down and
  347.     ' to the right.  The light acts as a highlight, and it looks like the original
  348.     ' image is a gray inset.
  349.     
  350.     ' First, create a copy of the destination.  Draw the light gray transparently,
  351.     ' and then draw the dark gray transparently
  352.     
  353.     hbmDisabled = CreateCompatibleBitmap(hDcScreen, Width, Height)
  354.     
  355.     hdcDisabled = CreateCompatibleDC(hDcScreen)
  356.     hbmDisabledSav = SelectObject(hdcDisabled, hbmDisabled)
  357.     hpalDisabledOld = SelectPalette(hdcDisabled, hPal, True)
  358.     RealizePalette hdcDisabled
  359.     'We used to fill the background with gray, instead copy the
  360.     'destination to memory DC.  This will allow a disabled image
  361.     'to be drawn over a background image.
  362.     BitBlt hdcDisabled, 0, 0, Width, Height, hdcDest, xDest, yDest, vbSrcCopy
  363.     
  364.     'When painting the monochrome bitmaps transparently onto the background
  365.     'we need a background color that is not the light color of the dark color
  366.     'Provide three choices to ensure a unique color is picked.
  367.     OleTranslateColor vbBlack, hPal, lMonoBkGrndChoices(0)
  368.     OleTranslateColor vbRed, hPal, lMonoBkGrndChoices(1)
  369.     OleTranslateColor vbBlue, hPal, lMonoBkGrndChoices(2)
  370.     
  371.     'Pick a background color choice that doesn't match
  372.     'the shadow or highlight color
  373.     For lIndex = 0 To 2
  374.         If lMonoBkGrndChoices(lIndex) <> dwSys3dHighlight And _
  375.                 lMonoBkGrndChoices(lIndex) <> dwSys3dShadow Then
  376.             'This color can be used for a mask
  377.             lMonoBkGrnd = lMonoBkGrndChoices(lIndex)
  378.             Exit For
  379.         End If
  380.     Next
  381.  
  382.     ' Now paint a the light color shifted and transparent over the background
  383.     ' It is not necessary to change the DIB section's color table
  384.     ' to equal the highlight color and mask color.  In fact, setting
  385.     ' the color table to anything besides black and white causes unpredictable
  386.     ' results (seen in win95 with IE4, using 256 colors).
  387.     ' Setting the Back and Text colors of the Monochrome bitmap, ensure
  388.     ' that the desired colors are produced.
  389.     With rgbnew(0)
  390.         .rgbRed = (vbWhite \ 2 ^ 16) And &HFF
  391.         .rgbGreen = (vbWhite \ 2 ^ 8) And &HFF
  392.         .rgbBlue = vbWhite And &HFF
  393.     End With
  394.     With rgbnew(1)
  395.         .rgbRed = (vbBlack \ 2 ^ 16) And &HFF
  396.         .rgbGreen = (vbBlack \ 2 ^ 8) And &HFF
  397.         .rgbBlue = vbBlack And &HFF
  398.     End With
  399.         
  400.     SetDIBColorTable hdcMonoSection, 0, 2, rgbnew(0)
  401.     
  402.     '...We can't pass a DIBSection to PaintTransparentDC(), so we need to
  403.     ' make a copy of our mono DIBSection.  Notice that we only need a monochrome
  404.     ' bitmap, but we must set its back/fore colors to the monochrome colors we
  405.     ' want (light gray and black), and PaintTransparentDC() will honor them.
  406.     hbmMono = CreateBitmap(Width, Height, 1, 1, ByVal 0&)
  407.     hdcMono = CreateCompatibleDC(hDcScreen)
  408.     hbmMonoSav = SelectObject(hdcMono, hbmMono)
  409.     SetMapMode hdcMono, GetMapMode(hDcSrc)
  410.     SetBkColor hdcMono, dwSys3dHighlight
  411.     SetTextColor hdcMono, lMonoBkGrnd
  412.     hpalMonoOld = SelectPalette(hdcMono, hPal, True)
  413.     RealizePalette hdcMono
  414.     BitBlt hdcMono, 0, 0, Width, Height, hdcMonoSection, 0, 0, vbSrcCopy
  415.  
  416.     '...We can go ahead and call PaintTransparentDC with our monochrome
  417.     ' copy
  418.     ' Draw this transparently over the disabled bitmap
  419.     '...Don't forget to shift right and left....
  420.     PaintTransparentDC hdcDisabled, 1, 1, Width, Height, hdcMono, 0, 0, lMonoBkGrnd, hPal
  421.     
  422.     ' Now draw a transparent copy, using dark gray where the monochrome had
  423.     ' black, and transparent elsewhere.  We'll use a transparent color of black.
  424.  
  425.     '...We can't pass a DIBSection to PaintTransparentDC(), so we need to
  426.     ' make a copy of our mono DIBSection.  Notice that we only need a monochrome
  427.     ' bitmap, but we must set its back/fore colors to the monochrome colors we
  428.     ' want (dark gray and black), and PaintTransparentDC() will honor them.
  429.     ' Use hbmMono and hdcMono; already created for first color
  430.     SetBkColor hdcMono, dwSys3dShadow
  431.     SetTextColor hdcMono, lMonoBkGrnd
  432.     BitBlt hdcMono, 0, 0, Width, Height, hdcMonoSection, 0, 0, vbSrcCopy
  433.  
  434.     '...We can go ahead and call PaintTransparentDC with our monochrome
  435.     ' copy
  436.     ' Draw this transparently over the disabled bitmap
  437.     PaintTransparentDC hdcDisabled, 0, 0, Width, Height, hdcMono, 0, 0, lMonoBkGrnd, hPal
  438.     BitBlt hdcDest, xDest, yDest, Width, Height, hdcDisabled, 0, 0, vbSrcCopy
  439.     ' Okay, we're done!
  440.     SelectPalette hdcDisabled, hpalDisabledOld, True
  441.     RealizePalette hdcDisabled
  442.     DeleteObject SelectObject(hdcMonoSection, hbmMonoSectionSav)
  443.     DeleteDC hdcMonoSection
  444.     DeleteObject SelectObject(hdcDisabled, hbmDisabledSav)
  445.     DeleteDC hdcDisabled
  446.     DeleteObject SelectObject(hdcMono, hbmMonoSav)
  447.     SelectPalette hdcMono, hpalMonoOld, True
  448.     RealizePalette hdcMono
  449.     DeleteDC hdcMono
  450.     ReleaseDC 0&, hDcScreen
  451. End Sub
  452.  
  453. '-------------------------------------------------------------------------
  454. 'Purpose:   Draws a transparent bitmap to a DC.  The pixels of the passed
  455. '           bitmap that match the passed mask color will not be painted
  456. '           to the destination DC
  457. 'In:
  458. '   [hdcDest]
  459. '           Device context to paint the picture on
  460. '   [xDest]
  461. '           X coordinate of the upper left corner of the area that the
  462. '           picture is to be painted on. (in pixels)
  463. '   [yDest]
  464. '           Y coordinate of the upper left corner of the area that the
  465. '           picture is to be painted on. (in pixels)
  466. '   [Width]
  467. '           Width of picture area to paint in pixels.  Note: If this value
  468. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  469. '           instead of the pictures' width in pixels), this procedure will
  470. '           attempt to create bitmaps that require outrageous
  471. '           amounts of memory.
  472. '   [Height]
  473. '           Height of picture area to paint in pixels.  Note: If this
  474. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  475. '           twips instead of the pictures' height in pixels), this
  476. '           procedure will attempt to create bitmaps that require
  477. '           outrageous amounts of memory.
  478. '   [hdcSrc]
  479. '           Device context that contains the source picture
  480. '   [xSrc]
  481. '           X coordinate of the upper left corner of the area in the picture
  482. '           to use as the source. (in pixels)
  483. '   [ySrc]
  484. '           Y coordinate of the upper left corner of the area in the picture
  485. '           to use as the source. (in pixels)
  486. '   [clrMask]
  487. '           Color of pixels to be masked out
  488. '   [hPal]
  489. '           Handle of palette to select into the memory DC's used to create
  490. '           the painting effect.
  491. '           If not provided, a HalfTone palette is used.
  492. '-------------------------------------------------------------------------
  493. Public Sub PaintTransparentDC(ByVal hdcDest As Long, _
  494.                                     ByVal xDest As Long, _
  495.                                     ByVal yDest As Long, _
  496.                                     ByVal Width As Long, _
  497.                                     ByVal Height As Long, _
  498.                                     ByVal hDcSrc As Long, _
  499.                                     ByVal xSrc As Long, _
  500.                                     ByVal ySrc As Long, _
  501.                                     ByVal clrMask As OLE_COLOR, _
  502.                                     Optional ByVal hPal As Long = 0)
  503. Attribute PaintTransparentDC.VB_Description = "Paints an image with transparent pixels defined by the mask color.  Accepts an hDC as its image source."
  504.     Dim hdcMask As Long        'HDC of the created mask image
  505.     Dim hdcColor As Long       'HDC of the created color image
  506.     Dim hbmMask As Long        'Bitmap handle to the mask image
  507.     Dim hbmColor As Long       'Bitmap handle to the color image
  508.     Dim hbmColorOld As Long
  509.     Dim hbmMaskOld As Long
  510.     Dim hPalOld As Long
  511.     Dim hDcScreen As Long
  512.     Dim hdcScnBuffer As Long         'Buffer to do all work on
  513.     Dim hbmScnBuffer As Long
  514.     Dim hbmScnBufferOld As Long
  515.     Dim hPalBufferOld As Long
  516.     Dim lMaskColor As Long
  517.     
  518.     hDcScreen = GetDC(0&)
  519.     'Validate palette
  520.     If hPal = 0 Then
  521.         hPal = m_hpalHalftone
  522.     End If
  523.     OleTranslateColor clrMask, hPal, lMaskColor
  524.     
  525.     'Create a color bitmap to server as a copy of the destination
  526.     'Do all work on this bitmap and then copy it back over the destination
  527.     'when it's done.
  528.     hbmScnBuffer = CreateCompatibleBitmap(hDcScreen, Width, Height)
  529.     'Create DC for screen buffer
  530.     hdcScnBuffer = CreateCompatibleDC(hDcScreen)
  531.     hbmScnBufferOld = SelectObject(hdcScnBuffer, hbmScnBuffer)
  532.     hPalBufferOld = SelectPalette(hdcScnBuffer, hPal, True)
  533.     RealizePalette hdcScnBuffer
  534.     'Copy the destination to the screen buffer
  535.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcDest, xDest, yDest, vbSrcCopy
  536.     
  537.     'Create a (color) bitmap for the cover (can't use CompatibleBitmap with
  538.     'hdcSrc, because this will create a DIB section if the original bitmap
  539.     'is a DIB section)
  540.     hbmColor = CreateCompatibleBitmap(hDcScreen, Width, Height)
  541.     'Now create a monochrome bitmap for the mask
  542.     hbmMask = CreateBitmap(Width, Height, 1, 1, ByVal 0&)
  543.     'First, blt the source bitmap onto the cover.  We do this first
  544.     'and then use it instead of the source bitmap
  545.     'because the source bitmap may be
  546.     'a DIB section, which behaves differently than a bitmap.
  547.     '(Specifically, copying from a DIB section to a monochrome bitmap
  548.     'does a nearest-color selection rather than painting based on the
  549.     'backcolor and forecolor.
  550.     hdcColor = CreateCompatibleDC(hDcScreen)
  551.     hbmColorOld = SelectObject(hdcColor, hbmColor)
  552.     hPalOld = SelectPalette(hdcColor, hPal, True)
  553.     RealizePalette hdcColor
  554.     'In case hdcSrc contains a monochrome bitmap, we must set the destination
  555.     'foreground/background colors according to those currently set in hdcSrc
  556.     '(because Windows will associate these colors with the two monochrome colors)
  557.     SetBkColor hdcColor, GetBkColor(hDcSrc)
  558.     SetTextColor hdcColor, GetTextColor(hDcSrc)
  559.     BitBlt hdcColor, 0, 0, Width, Height, hDcSrc, xSrc, ySrc, vbSrcCopy
  560.     'Paint the mask.  What we want is white at the transparent color
  561.     'from the source, and black everywhere else.
  562.     hdcMask = CreateCompatibleDC(hDcScreen)
  563.     hbmMaskOld = SelectObject(hdcMask, hbmMask)
  564.  
  565.     'When bitblt'ing from color to monochrome, Windows sets to 1
  566.     'all pixels that match the background color of the source DC.  All
  567.     'other bits are set to 0.
  568.     SetBkColor hdcColor, lMaskColor
  569.     SetTextColor hdcColor, vbWhite
  570.     BitBlt hdcMask, 0, 0, Width, Height, hdcColor, 0, 0, vbSrcCopy
  571.     'Paint the rest of the cover bitmap.
  572.     '
  573.     'What we want here is black at the transparent color, and
  574.     'the original colors everywhere else.  To do this, we first
  575.     'paint the original onto the cover (which we already did), then we
  576.     'AND the inverse of the mask onto that using the DSna ternary raster
  577.     'operation (0x00220326 - see Win32 SDK reference, Appendix, "Raster
  578.     'Operation Codes", "Ternary Raster Operations", or search in MSDN
  579.     'for 00220326).  DSna [reverse polish] means "(not SRC) and DEST".
  580.     '
  581.     'When bitblt'ing from monochrome to color, Windows transforms all white
  582.     'bits (1) to the background color of the destination hdc.  All black (0)
  583.     'bits are transformed to the foreground color.
  584.     SetTextColor hdcColor, vbBlack
  585.     SetBkColor hdcColor, vbWhite
  586.     BitBlt hdcColor, 0, 0, Width, Height, hdcMask, 0, 0, DSna
  587.     'Paint the Mask to the Screen buffer
  588.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcMask, 0, 0, vbSrcAnd
  589.     'Paint the Color to the Screen buffer
  590.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcColor, 0, 0, vbSrcPaint
  591.     'Copy the screen buffer to the screen
  592.     BitBlt hdcDest, xDest, yDest, Width, Height, hdcScnBuffer, 0, 0, vbSrcCopy
  593.     'All done!
  594.     DeleteObject SelectObject(hdcColor, hbmColorOld)
  595.     SelectPalette hdcColor, hPalOld, True
  596.     RealizePalette hdcColor
  597.     DeleteDC hdcColor
  598.     DeleteObject SelectObject(hdcScnBuffer, hbmScnBufferOld)
  599.     SelectPalette hdcScnBuffer, hPalBufferOld, True
  600.     RealizePalette hdcScnBuffer
  601.     DeleteDC hdcScnBuffer
  602.     
  603.     DeleteObject SelectObject(hdcMask, hbmMaskOld)
  604.     DeleteDC hdcMask
  605.     ReleaseDC 0&, hDcScreen
  606. End Sub
  607.  
  608. '-------------------------------------------------------------------------
  609. 'Purpose:   Draws a transparent bitmap to a DC.  The pixels of the passed
  610. '           bitmap that match the passed mask color will not be painted
  611. '           to the destination DC
  612. 'In:
  613. '   [hdcDest]
  614. '           Device context to paint the picture on
  615. '   [xDest]
  616. '           X coordinate of the upper left corner of the area that the
  617. '           picture is to be painted on. (in pixels)
  618. '   [yDest]
  619. '           Y coordinate of the upper left corner of the area that the
  620. '           picture is to be painted on. (in pixels)
  621. '   [Width]
  622. '           Width of picture area to paint in pixels.  Note: If this value
  623. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  624. '           instead of the pictures' width in pixels), this procedure will
  625. '           attempt to create bitmaps that require outrageous
  626. '           amounts of memory.
  627. '   [Height]
  628. '           Height of picture area to paint in pixels.  Note: If this
  629. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  630. '           twips instead of the pictures' height in pixels), this
  631. '           procedure will attempt to create bitmaps that require
  632. '           outrageous amounts of memory.
  633. '   [picSource]
  634. '           Standard Picture object to be used as the image source
  635. '   [xSrc]
  636. '           X coordinate of the upper left corner of the area in the picture
  637. '           to use as the source. (in pixels)
  638. '           Ignored if picSource is an Icon.
  639. '   [ySrc]
  640. '           Y coordinate of the upper left corner of the area in the picture
  641. '           to use as the source. (in pixels)
  642. '           Ignored if picSource is an Icon.
  643. '   [clrMask]
  644. '           Color of pixels to be masked out
  645. '   [hPal]
  646. '           Handle of palette to select into the memory DC's used to create
  647. '           the painting effect.
  648. '           If not provided, a HalfTone palette is used.
  649. '-------------------------------------------------------------------------
  650. Public Sub PaintTransparentStdPic(ByVal hdcDest As Long, _
  651.                                     ByVal xDest As Long, _
  652.                                     ByVal yDest As Long, _
  653.                                     ByVal Width As Long, _
  654.                                     ByVal Height As Long, _
  655.                                     ByVal picSource As Picture, _
  656.                                     ByVal xSrc As Long, _
  657.                                     ByVal ySrc As Long, _
  658.                                     ByVal clrMask As OLE_COLOR, _
  659.                                     Optional ByVal hPal As Long = 0)
  660. Attribute PaintTransparentStdPic.VB_Description = "Paints an image with transparent pixels defined by the mask color.  Accepts a picture object as its image source."
  661.     Dim hDcSrc As Long         'HDC that the source bitmap is selected into
  662.     Dim hbmMemSrcOld As Long
  663.     Dim hbmMemSrc As Long
  664.     Dim udtRect As RECT
  665.     Dim hbrMask As Long
  666.     Dim lMaskColor As Long
  667.     Dim hDcScreen As Long
  668.     Dim hPalOld As Long
  669.     'Verify that the passed picture is a Bitmap
  670.     If picSource Is Nothing Then GoTo PaintTransparentStdPic_InvalidParam
  671.     
  672.     Select Case picSource.Type
  673.         Case vbPicTypeBitmap
  674.             hDcScreen = GetDC(0&)
  675.             'Validate palette
  676.             If hPal = 0 Then
  677.                 hPal = m_hpalHalftone
  678.             End If
  679.             'Select passed picture into an HDC
  680.             hDcSrc = CreateCompatibleDC(hDcScreen)
  681.             hbmMemSrcOld = SelectObject(hDcSrc, picSource.handle)
  682.             hPalOld = SelectPalette(hDcSrc, hPal, True)
  683.             RealizePalette hDcSrc
  684.             'Draw the bitmap
  685.             PaintTransparentDC hdcDest, xDest, yDest, Width, Height, hDcSrc, xSrc, ySrc, clrMask, hPal
  686.             
  687.             SelectObject hDcSrc, hbmMemSrcOld
  688.             SelectPalette hDcSrc, hPalOld, True
  689.             RealizePalette hDcSrc
  690.             DeleteDC hDcSrc
  691.             ReleaseDC 0&, hDcScreen
  692.         Case vbPicTypeIcon
  693.             'Create a bitmap and select it into an DC
  694.             hDcScreen = GetDC(0&)
  695.             'Validate palette
  696.             If hPal = 0 Then
  697.                 hPal = m_hpalHalftone
  698.             End If
  699.             hDcSrc = CreateCompatibleDC(hDcScreen)
  700.             hbmMemSrc = CreateCompatibleBitmap(hDcScreen, Width, Height)
  701.             hbmMemSrcOld = SelectObject(hDcSrc, hbmMemSrc)
  702.             hPalOld = SelectPalette(hDcSrc, hPal, True)
  703.             RealizePalette hDcSrc
  704.             'Draw Icon onto DC
  705.             udtRect.Bottom = Height
  706.             udtRect.Right = Width
  707.             OleTranslateColor clrMask, 0&, lMaskColor
  708.             hbrMask = CreateSolidBrush(lMaskColor)
  709.             FillRect hDcSrc, udtRect, hbrMask
  710.             DeleteObject hbrMask
  711.             DrawIcon hDcSrc, 0, 0, picSource.handle
  712.             'Draw Transparent image
  713.             PaintTransparentDC hdcDest, xDest, yDest, Width, Height, hDcSrc, 0, 0, lMaskColor, hPal
  714.             'Clean up
  715.             DeleteObject SelectObject(hDcSrc, hbmMemSrcOld)
  716.             SelectPalette hDcSrc, hPalOld, True
  717.             RealizePalette hDcSrc
  718.             DeleteDC hDcSrc
  719.             ReleaseDC 0&, hDcScreen
  720.         Case Else
  721.             GoTo PaintTransparentStdPic_InvalidParam
  722.     End Select
  723.     Exit Sub
  724. PaintTransparentStdPic_InvalidParam:
  725. '    Err.Raise giINVALID_PICTURE
  726.     Exit Sub
  727. End Sub
  728.  
  729. '-------------------------------------------------------------------------
  730. 'Purpose:   Draws a standard picture object to a DC
  731. 'In:
  732. '   [hdcDest]
  733. '           Handle of the device context to paint the picture on
  734. '   [xDest]
  735. '           X coordinate of the upper left corner of the area that the
  736. '           picture is to be painted on. (in pixels)
  737. '   [yDest]
  738. '           Y coordinate of the upper left corner of the area that the
  739. '           picture is to be painted on. (in pixels)
  740. '   [Width]
  741. '           Width of picture area to paint in pixels.  Note: If this value
  742. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  743. '           instead of the pictures' width in pixels), this procedure will
  744. '           attempt to create bitmaps that require outrageous
  745. '           amounts of memory.
  746. '   [Height]
  747. '           Height of picture area to paint in pixels.  Note: If this
  748. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  749. '           twips instead of the pictures' height in pixels), this
  750. '           procedure will attempt to create bitmaps that require
  751. '           outrageous amounts of memory.
  752. '   [picSource]
  753. '           Standard Picture object to be used as the image source
  754. '   [xSrc]
  755. '           X coordinate of the upper left corner of the area in the picture
  756. '           to use as the source. (in pixels)
  757. '           Ignored if picSource is an Icon.
  758. '   [ySrc]
  759. '           Y coordinate of the upper left corner of the area in the picture
  760. '           to use as the source. (in pixels)
  761. '           Ignored if picSource is an Icon.
  762. '   [hPal]
  763. '           Handle of palette to select into the memory DC's used to create
  764. '           the painting effect.
  765. '           If not provided, a HalfTone palette is used.
  766. '-------------------------------------------------------------------------
  767. Public Sub PaintNormalStdPic(ByVal hdcDest As Long, _
  768.                                     ByVal xDest As Long, _
  769.                                     ByVal yDest As Long, _
  770.                                     ByVal Width As Long, _
  771.                                     ByVal Height As Long, _
  772.                                     ByVal picSource As Picture, _
  773.                                     ByVal xSrc As Long, _
  774.                                     ByVal ySrc As Long, _
  775.                                     Optional ByVal hPal As Long = 0)
  776. Attribute PaintNormalStdPic.VB_Description = "Paints an image provided by a picture object to an hDC with no effects."
  777.     Dim hdcTemp As Long
  778.     Dim hPalOld As Long
  779.     Dim hbmMemSrcOld As Long
  780.     Dim hDcScreen As Long
  781.     Dim hbmMemSrc As Long
  782.     'Validate that a bitmap was passed in
  783.     If picSource Is Nothing Then GoTo PaintNormalStdPic_InvalidParam
  784.     Select Case picSource.Type
  785.         Case vbPicTypeBitmap
  786.             If hPal = 0 Then
  787.                 hPal = m_hpalHalftone
  788.             End If
  789.             hDcScreen = GetDC(0&)
  790.             'Create a DC to select bitmap into
  791.             hdcTemp = CreateCompatibleDC(hDcScreen)
  792.             hPalOld = SelectPalette(hdcTemp, hPal, True)
  793.             RealizePalette hdcTemp
  794.             'Select bitmap into DC
  795.             hbmMemSrcOld = SelectObject(hdcTemp, picSource.handle)
  796.             'Copy to destination DC
  797.             BitBlt hdcDest, xDest, yDest, Width, Height, hdcTemp, xSrc, ySrc, vbSrcCopy
  798.             'Cleanup
  799.             SelectObject hdcTemp, hbmMemSrcOld
  800.             SelectPalette hdcTemp, hPalOld, True
  801.             RealizePalette hdcTemp
  802.             DeleteDC hdcTemp
  803.             ReleaseDC 0&, hDcScreen
  804.         Case vbPicTypeIcon
  805.             'Create a bitmap and select it into an DC
  806.             'Draw Icon onto DC
  807.             DrawIconEx hdcDest, xDest, yDest, picSource.handle, Width, Height, 0&, 0&, DI_NORMAL
  808.         Case Else
  809.             GoTo PaintNormalStdPic_InvalidParam
  810.     End Select
  811.     Exit Sub
  812. PaintNormalStdPic_InvalidParam:
  813.     'Err.Raise giINVALID_PICTURE
  814. End Sub
  815.  
  816. '-------------------------------------------------------------------------
  817. 'Purpose:   Draws a standard picture object to a DC in Greyscale
  818. 'In:
  819. '   [hdcDest]
  820. '           Handle of the device context to paint the picture on
  821. '   [xDest]
  822. '           X coordinate of the upper left corner of the area that the
  823. '           picture is to be painted on. (in pixels)
  824. '   [yDest]
  825. '           Y coordinate of the upper left corner of the area that the
  826. '           picture is to be painted on. (in pixels)
  827. '   [Width]
  828. '           Width of picture area to paint in pixels.  Note: If this value
  829. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  830. '           instead of the pictures' width in pixels), this procedure will
  831. '           attempt to create bitmaps that require outrageous
  832. '           amounts of memory.
  833. '   [Height]
  834. '           Height of picture area to paint in pixels.  Note: If this
  835. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  836. '           twips instead of the pictures' height in pixels), this
  837. '           procedure will attempt to create bitmaps that require
  838. '           outrageous amounts of memory.
  839. '   [picSource]
  840. '           Standard Picture object to be used as the image source
  841. '   [xSrc]
  842. '           X coordinate of the upper left corner of the area in the picture
  843. '           to use as the source. (in pixels)
  844. '           Ignored if picSource is an Icon.
  845. '   [ySrc]
  846. '           Y coordinate of the upper left corner of the area in the picture
  847. '           to use as the source. (in pixels)
  848. '           Ignored if picSource is an Icon.
  849. '   [hPal]
  850. '           Handle of palette to select into the memory DC's used to create
  851. '           the painting effect.
  852. '           If not provided, a HalfTone palette is used.
  853. '-------------------------------------------------------------------------
  854. Public Sub PaintGreyScaleStdPic(ByVal hdcDest As Long, _
  855.                                     ByVal xDest As Long, _
  856.                                     ByVal yDest As Long, _
  857.                                     ByVal Width As Long, _
  858.                                     ByVal Height As Long, _
  859.                                     ByVal picSource As Picture, _
  860.                                     ByVal xSrc As Long, _
  861.                                     ByVal ySrc As Long, _
  862.                                     Optional ByVal hPal As Long = 0)
  863.     Dim hdcTemp As Long
  864.     Dim hPalOld As Long
  865.     Dim hbmMemSrcOld As Long
  866.     Dim hDcScreen As Long
  867.     Dim hbmMemSrc As Long
  868.     'Validate that a bitmap was passed in
  869.     If picSource Is Nothing Then GoTo PaintGreyScaleStdPic_InvalidParam
  870.     Select Case picSource.Type
  871.         Case vbPicTypeBitmap
  872.             If hPal = 0 Then
  873.                 hPal = m_hpalHalftone
  874.             End If
  875.             hDcScreen = GetDC(0&)
  876.             'Create a DC to select bitmap into
  877.             hdcTemp = CreateCompatibleDC(hDcScreen)
  878.             hPalOld = SelectPalette(hdcTemp, hPal, True)
  879.             RealizePalette hdcTemp
  880.             'Select bitmap into DC
  881.             hbmMemSrcOld = SelectObject(hdcTemp, picSource.handle)
  882.             'Copy to destination DC
  883.             BitBlt hdcDest, xDest, yDest, Width, Height, hdcTemp, xSrc, ySrc, vbSrcAnd
  884.             'Cleanup
  885.             SelectObject hdcTemp, hbmMemSrcOld
  886.             SelectPalette hdcTemp, hPalOld, True
  887.             RealizePalette hdcTemp
  888.             DeleteDC hdcTemp
  889.             ReleaseDC 0&, hDcScreen
  890.         Case vbPicTypeIcon
  891.             'Create a bitmap and select it into an DC
  892.             'Draw Icon onto DC
  893.             DrawIconEx hdcDest, xDest, yDest, picSource.handle, Width, Height, 0&, 0&, DI_NORMAL
  894.         Case Else
  895.             GoTo PaintGreyScaleStdPic_InvalidParam
  896.     End Select
  897.     Exit Sub
  898. PaintGreyScaleStdPic_InvalidParam:
  899.     'Err.Raise giINVALID_PICTURE
  900. End Sub
  901.  
  902. 'kdq 10/19/98 added for monochrome look on bitmap
  903. Public Sub PaintGreyScaleCornerStdPic(ByVal hdcDest As Long, _
  904.                                     ByVal xDest As Long, _
  905.                                     ByVal yDest As Long, _
  906.                                     ByVal Width As Long, _
  907.                                     ByVal Height As Long, _
  908.                                     ByVal picSource As Picture, _
  909.                                     ByVal xSrc As Long, _
  910.                                     ByVal ySrc As Long, _
  911.                                     Optional ByVal hPal As Long = 0)
  912.    '
  913.    ' 32-Bit GreyScale BitBlt Function
  914.    ' Written by Geoff Glaze 2/13/98
  915.    '
  916.    ' Purpose:
  917.    '    Creates a greyscale version of a bitmap
  918.    '
  919.    ' Parameters ************************************************************
  920.    '   hDestDC:     Destination device context
  921.    '   x, y:        Upper-left destination coordinates (pixels)
  922.    '   nWidth:      Width of destination
  923.    '   nHeight:     Height of destination
  924.    '   hSrcDC:      Source device context
  925.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  926.    ' ***********************************************************************
  927.    
  928.     Dim hDcSrc As Long         'HDC that the source bitmap is selected into
  929.     Dim hbmMemSrcOld As Long
  930.     Dim hbmMemSrc As Long
  931.     Dim udtRect As RECT
  932.     Dim hbrMask As Long
  933.     Dim lMaskColor As Long
  934.     Dim hDcScreen As Long
  935.     Dim hPalOld As Long
  936.     Dim hBrush As Long
  937.     'Verify that the passed picture is a Bitmap
  938.     If picSource Is Nothing Then GoTo PaintGreyScaleCornerStdPic_InvalidParam
  939.     
  940.     hBrush = CreateSolidBrush(RGB(100, 100, 100))
  941.     Select Case picSource.Type
  942.         Case vbPicTypeBitmap
  943.             Call DrawState(hdcDest, hBrush, 0&, picSource, 0&, xDest, yDest, Width, Height, DST_BITMAP Or DSS_MONO)
  944.         Case vbPicTypeIcon
  945.             Call DrawState(hdcDest, hBrush, 0&, picSource, 0&, xDest, yDest, Width, Height, DST_ICON Or DSS_MONO)
  946.         Case Else
  947.             GoTo PaintGreyScaleCornerStdPic_InvalidParam
  948.     End Select
  949.     Exit Sub
  950.  
  951. PaintGreyScaleCornerStdPic_InvalidParam:
  952.     'Err.Raise giINVALID_PICTURE
  953.     Exit Sub
  954.    
  955. End Sub
  956.  
  957. Private Sub Class_Initialize()
  958.     Dim hDcScreen As Long
  959.     'Create halftone palette
  960.     hDcScreen = GetDC(0&)
  961.     m_hpalHalftone = CreateHalftonePalette(hDcScreen)
  962.     ReleaseDC 0&, hDcScreen
  963. End Sub
  964.  
  965. Private Sub Class_Terminate()
  966.     DeleteObject m_hpalHalftone
  967. End Sub
  968.