home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / axpanel / clspnttl.cls < prev    next >
Encoding:
Visual Basic class definition  |  1998-03-19  |  50.0 KB  |  1,188 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. '*****************************************************************
  12. '
  13. '   POPUPCOMMAND CONTROL
  14. '
  15. '   This code and control is absolutely freeware!
  16. '
  17. '   You have a royalty-free right to use, modify, reproduce and distribute
  18. '   the source code and control (and/or any modified version) in any way
  19. '   you find useful, provided that you agree that the authors have no warranty,
  20. '   obligations or liability for any code distributed in this project group.
  21. '
  22. ' Copyright ⌐ 1998 by Geoff Glaze
  23. '
  24. '   (Some parts borrowed from Microsoft)
  25. '
  26. '*****************************************************************
  27.  
  28.  
  29. '-------------------------------------------------------------------------
  30. 'This class provides methods needed for painting masked bitmaps and
  31. 'disabled or embossed bitmaps and icons
  32. '-------------------------------------------------------------------------
  33.  
  34. Option Explicit
  35.  
  36. Private m_hpalHalftone As Long  'Halftone created for default palette use
  37.  
  38. '-------------------------------------------------------------------------
  39. 'Purpose:   Creates a disabled-appearing (grayed) bitmap, given any format of
  40. '           input bitmap.
  41. 'In:
  42. '   [hdcDest]
  43. '           Device context to paint the picture on
  44. '   [xDest]
  45. '           X coordinate of the upper left corner of the area that the
  46. '           picture is to be painted on. (in pixels)
  47. '   [yDest]
  48. '           Y coordinate of the upper left corner of the area that the
  49. '           picture is to be painted on. (in pixels)
  50. '   [Width]
  51. '           Width of picture area to paint in pixels.  Note: If this value
  52. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  53. '           instead of the pictures' width in pixels), this procedure will
  54. '           attempt to create bitmaps that require outrageous
  55. '           amounts of memory.
  56. '   [Height]
  57. '           Height of picture area to paint in pixels.  Note: If this
  58. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  59. '           twips instead of the pictures' height in pixels), this
  60. '           procedure will attempt to create bitmaps that require
  61. '           outrageous amounts of memory.
  62. '   [picSource]
  63. '           Standard Picture object to be used as the image source
  64. '   [xSrc]
  65. '           X coordinate of the upper left corner of the area in the picture
  66. '           to use as the source. (in pixels)
  67. '           Ignored if picSource is an Icon.
  68. '   [ySrc]
  69. '           Y coordinate of the upper left corner of the area in the picture
  70. '           to use as the source. (in pixels)
  71. '           Ignored if picSource is an Icon.
  72. '   [clrMask]
  73. '           Color of pixels to be masked out
  74. '   [clrHighlight]
  75. '           Color to be used as outline highlight
  76. '   [clrShadow]
  77. '           Color to be used as outline shadow
  78. '   [hPal]
  79. '           Handle of palette to select into the memory DC's used to create
  80. '           the painting effect.
  81. '           If not provided, a HalfTone palette is used.
  82. '-------------------------------------------------------------------------
  83. Public Sub PaintDisabledStdPic(ByVal hdcDest As Long, _
  84.                                 ByVal xDest As Long, _
  85.                                 ByVal yDest As Long, _
  86.                                 ByVal Width As Long, _
  87.                                 ByVal Height As Long, _
  88.                                 ByVal picSource As StdPicture, _
  89.                                 ByVal xSrc As Long, _
  90.                                 ByVal ySrc As Long, _
  91.                                 Optional ByVal clrMask As OLE_COLOR = vbWhite, _
  92.                                 Optional ByVal clrHighlight As OLE_COLOR = vb3DHighlight, _
  93.                                 Optional ByVal clrShadow As OLE_COLOR = vb3DShadow, _
  94.                                 Optional ByVal hPal As Long = 0)
  95.     Dim hdcSrc As Long         'HDC that the source bitmap is selected into
  96.     Dim hbmMemSrcOld As Long
  97.     Dim hbmMemSrc As Long
  98.     Dim udtRect As RECT
  99.     Dim hbrMask As Long
  100.     Dim lMaskColor As Long
  101.     Dim hdcScreen As Long
  102.     Dim hPalOld As Long
  103.     
  104.     'Verify that the passed picture is not nothing
  105.     If picSource Is Nothing Then GoTo PaintDisabledDC_InvalidParam
  106.     Select Case picSource.Type
  107.         Case vbPicTypeBitmap
  108.             'Select passed picture into an HDC
  109.             hdcScreen = GetDC(0&)
  110.             'Validate palette
  111.             If hPal = 0 Then
  112.                 hPal = m_hpalHalftone
  113.             End If
  114.             hdcSrc = CreateCompatibleDC(hdcScreen)
  115.             hbmMemSrcOld = SelectObject(hdcSrc, picSource.handle)
  116.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  117.             RealizePalette hdcSrc
  118.             
  119.             'Draw the bitmap
  120.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, clrMask, clrHighlight, clrShadow, hPal
  121.             
  122.             SelectObject hdcSrc, hbmMemSrcOld
  123.             SelectPalette hdcSrc, hPalOld, True
  124.             RealizePalette hdcSrc
  125.             DeleteDC hdcSrc
  126.             ReleaseDC 0&, hdcScreen
  127.         Case vbPicTypeIcon
  128.             'Create a bitmap and select it into a DC
  129.             hdcScreen = GetDC(0&)
  130.             'Validate palette
  131.             If hPal = 0 Then
  132.                 hPal = m_hpalHalftone
  133.             End If
  134.             hdcSrc = CreateCompatibleDC(hdcScreen)
  135.             hbmMemSrc = CreateCompatibleBitmap(hdcScreen, Width, Height)
  136.             hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
  137.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  138.             RealizePalette hdcSrc
  139.             'Draw Icon onto DC
  140.             udtRect.Bottom = Height
  141.             udtRect.Right = Width
  142.             OleTranslateColor clrMask, 0&, lMaskColor
  143.             SetBkColor hdcSrc, lMaskColor
  144.             hbrMask = CreateSolidBrush(lMaskColor)
  145.             FillRect hdcSrc, udtRect, hbrMask
  146.             DeleteObject hbrMask
  147.             DrawIcon hdcSrc, 0, 0, picSource.handle
  148.             'Draw Disabled image
  149.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hdcSrc, 0&, 0&, clrMask, clrHighlight, clrShadow, hPal
  150.             'Clean up
  151.             SelectPalette hdcSrc, hPalOld, True
  152.             RealizePalette hdcSrc
  153.             DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
  154.             DeleteDC hdcSrc
  155.             ReleaseDC 0&, hdcScreen
  156.         Case Else
  157.             GoTo PaintDisabledDC_InvalidParam
  158.     End Select
  159.     Exit Sub
  160. PaintDisabledDC_InvalidParam:
  161.     Error.Raise giINVALID_PICTURE
  162.     Exit Sub
  163. End Sub
  164.  
  165. '-------------------------------------------------------------------------
  166. 'Purpose:   Creates a disabled-appearing (grayed) bitmap, given any format of
  167. '           input bitmap.
  168. 'In:
  169. '   [hdcDest]
  170. '           Device context to paint the picture on
  171. '   [xDest]
  172. '           X coordinate of the upper left corner of the area that the
  173. '           picture is to be painted on. (in pixels)
  174. '   [yDest]
  175. '           Y coordinate of the upper left corner of the area that the
  176. '           picture is to be painted on. (in pixels)
  177. '   [Width]
  178. '           Width of picture area to paint in pixels.  Note: If this value
  179. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  180. '           instead of the pictures' width in pixels), this procedure will
  181. '           attempt to create bitmaps that require outrageous
  182. '           amounts of memory.
  183. '   [Height]
  184. '           Height of picture area to paint in pixels.  Note: If this
  185. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  186. '           twips instead of the pictures' height in pixels), this
  187. '           procedure will attempt to create bitmaps that require
  188. '           outrageous amounts of memory.
  189. '   [hdcSrc]
  190. '           Device context that contains the source picture
  191. '   [xSrc]
  192. '           X coordinate of the upper left corner of the area in the picture
  193. '           to use as the source. (in pixels)
  194. '   [ySrc]
  195. '           Y coordinate of the upper left corner of the area in the picture
  196. '           to use as the source. (in pixels)
  197. '   [clrMask]
  198. '           Color of pixels to be masked out
  199. '   [clrHighlight]
  200. '           Color to be used as outline highlight
  201. '   [clrShadow]
  202. '           Color to be used as outline shadow
  203. '   [hPal]
  204. '           Handle of palette to select into the memory DC's used to create
  205. '           the painting effect.
  206. '           If not provided, a HalfTone palette is used.
  207. '-------------------------------------------------------------------------
  208. Public Sub PaintDisabledDC(ByVal hdcDest As Long, _
  209.                                 ByVal xDest As Long, _
  210.                                 ByVal yDest As Long, _
  211.                                 ByVal Width As Long, _
  212.                                 ByVal Height As Long, _
  213.                                 ByVal hdcSrc As Long, _
  214.                                 ByVal xSrc As Long, _
  215.                                 ByVal ySrc As Long, _
  216.                                 Optional ByVal clrMask As OLE_COLOR = vbWhite, _
  217.                                 Optional ByVal clrHighlight As OLE_COLOR = vb3DHighlight, _
  218.                                 Optional ByVal clrShadow As OLE_COLOR = vb3DShadow, _
  219.                                 Optional ByVal hPal As Long = 0)
  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.     Dim hdcMask As Long        'HDC of the created mask image
  504.     Dim hdcColor As Long       'HDC of the created color image
  505.     Dim hbmMask As Long        'Bitmap handle to the mask image
  506.     Dim hbmColor As Long       'Bitmap handle to the color image
  507.     Dim hbmColorOld As Long
  508.     Dim hbmMaskOld As Long
  509.     Dim hPalOld As Long
  510.     Dim hdcScreen As Long
  511.     Dim hdcScnBuffer As Long         'Buffer to do all work on
  512.     Dim hbmScnBuffer As Long
  513.     Dim hbmScnBufferOld As Long
  514.     Dim hPalBufferOld As Long
  515.     Dim lMaskColor As Long
  516.     
  517.     hdcScreen = GetDC(0&)
  518.     'Validate palette
  519.     If hPal = 0 Then
  520.         hPal = m_hpalHalftone
  521.     End If
  522.     OleTranslateColor clrMask, hPal, lMaskColor
  523.     
  524.     'Create a color bitmap to server as a copy of the destination
  525.     'Do all work on this bitmap and then copy it back over the destination
  526.     'when it's done.
  527.     hbmScnBuffer = CreateCompatibleBitmap(hdcScreen, Width, Height)
  528.     'Create DC for screen buffer
  529.     hdcScnBuffer = CreateCompatibleDC(hdcScreen)
  530.     hbmScnBufferOld = SelectObject(hdcScnBuffer, hbmScnBuffer)
  531.     hPalBufferOld = SelectPalette(hdcScnBuffer, hPal, True)
  532.     RealizePalette hdcScnBuffer
  533.     'Copy the destination to the screen buffer
  534.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcDest, xDest, yDest, vbSrcCopy
  535.     
  536.     'Create a (color) bitmap for the cover (can't use CompatibleBitmap with
  537.     'hdcSrc, because this will create a DIB section if the original bitmap
  538.     'is a DIB section)
  539.     hbmColor = CreateCompatibleBitmap(hdcScreen, Width, Height)
  540.     'Now create a monochrome bitmap for the mask
  541.     hbmMask = CreateBitmap(Width, Height, 1, 1, ByVal 0&)
  542.     'First, blt the source bitmap onto the cover.  We do this first
  543.     'and then use it instead of the source bitmap
  544.     'because the source bitmap may be
  545.     'a DIB section, which behaves differently than a bitmap.
  546.     '(Specifically, copying from a DIB section to a monochrome bitmap
  547.     'does a nearest-color selection rather than painting based on the
  548.     'backcolor and forecolor.
  549.     hdcColor = CreateCompatibleDC(hdcScreen)
  550.     hbmColorOld = SelectObject(hdcColor, hbmColor)
  551.     hPalOld = SelectPalette(hdcColor, hPal, True)
  552.     RealizePalette hdcColor
  553.     'In case hdcSrc contains a monochrome bitmap, we must set the destination
  554.     'foreground/background colors according to those currently set in hdcSrc
  555.     '(because Windows will associate these colors with the two monochrome colors)
  556.     SetBkColor hdcColor, GetBkColor(hdcSrc)
  557.     SetTextColor hdcColor, GetTextColor(hdcSrc)
  558.     BitBlt hdcColor, 0, 0, Width, Height, hdcSrc, xSrc, ySrc, vbSrcCopy
  559.     'Paint the mask.  What we want is white at the transparent color
  560.     'from the source, and black everywhere else.
  561.     hdcMask = CreateCompatibleDC(hdcScreen)
  562.     hbmMaskOld = SelectObject(hdcMask, hbmMask)
  563.  
  564.     'When bitblt'ing from color to monochrome, Windows sets to 1
  565.     'all pixels that match the background color of the source DC.  All
  566.     'other bits are set to 0.
  567.     SetBkColor hdcColor, lMaskColor
  568.     SetTextColor hdcColor, vbWhite
  569.     BitBlt hdcMask, 0, 0, Width, Height, hdcColor, 0, 0, vbSrcCopy
  570.     'Paint the rest of the cover bitmap.
  571.     '
  572.     'What we want here is black at the transparent color, and
  573.     'the original colors everywhere else.  To do this, we first
  574.     'paint the original onto the cover (which we already did), then we
  575.     'AND the inverse of the mask onto that using the DSna ternary raster
  576.     'operation (0x00220326 - see Win32 SDK reference, Appendix, "Raster
  577.     'Operation Codes", "Ternary Raster Operations", or search in MSDN
  578.     'for 00220326).  DSna [reverse polish] means "(not SRC) and DEST".
  579.     '
  580.     'When bitblt'ing from monochrome to color, Windows transforms all white
  581.     'bits (1) to the background color of the destination hdc.  All black (0)
  582.     'bits are transformed to the foreground color.
  583.     SetTextColor hdcColor, vbBlack
  584.     SetBkColor hdcColor, vbWhite
  585.     BitBlt hdcColor, 0, 0, Width, Height, hdcMask, 0, 0, DSna
  586.     'Paint the Mask to the Screen buffer
  587.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcMask, 0, 0, vbSrcAnd
  588.     'Paint the Color to the Screen buffer
  589.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcColor, 0, 0, vbSrcPaint
  590.     'Copy the screen buffer to the screen
  591.     BitBlt hdcDest, xDest, yDest, Width, Height, hdcScnBuffer, 0, 0, vbSrcCopy
  592.     'All done!
  593.     DeleteObject SelectObject(hdcColor, hbmColorOld)
  594.     SelectPalette hdcColor, hPalOld, True
  595.     RealizePalette hdcColor
  596.     DeleteDC hdcColor
  597.     DeleteObject SelectObject(hdcScnBuffer, hbmScnBufferOld)
  598.     SelectPalette hdcScnBuffer, hPalBufferOld, True
  599.     RealizePalette hdcScnBuffer
  600.     DeleteDC hdcScnBuffer
  601.     
  602.     DeleteObject SelectObject(hdcMask, hbmMaskOld)
  603.     DeleteDC hdcMask
  604.     ReleaseDC 0&, hdcScreen
  605. End Sub
  606.  
  607. '-------------------------------------------------------------------------
  608. 'Purpose:   Draws a transparent bitmap to a DC.  The pixels of the passed
  609. '           bitmap that match the passed mask color will not be painted
  610. '           to the destination DC
  611. 'In:
  612. '   [hdcDest]
  613. '           Device context to paint the picture on
  614. '   [xDest]
  615. '           X coordinate of the upper left corner of the area that the
  616. '           picture is to be painted on. (in pixels)
  617. '   [yDest]
  618. '           Y coordinate of the upper left corner of the area that the
  619. '           picture is to be painted on. (in pixels)
  620. '   [Width]
  621. '           Width of picture area to paint in pixels.  Note: If this value
  622. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  623. '           instead of the pictures' width in pixels), this procedure will
  624. '           attempt to create bitmaps that require outrageous
  625. '           amounts of memory.
  626. '   [Height]
  627. '           Height of picture area to paint in pixels.  Note: If this
  628. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  629. '           twips instead of the pictures' height in pixels), this
  630. '           procedure will attempt to create bitmaps that require
  631. '           outrageous amounts of memory.
  632. '   [picSource]
  633. '           Standard Picture object to be used as the image source
  634. '   [xSrc]
  635. '           X coordinate of the upper left corner of the area in the picture
  636. '           to use as the source. (in pixels)
  637. '           Ignored if picSource is an Icon.
  638. '   [ySrc]
  639. '           Y coordinate of the upper left corner of the area in the picture
  640. '           to use as the source. (in pixels)
  641. '           Ignored if picSource is an Icon.
  642. '   [clrMask]
  643. '           Color of pixels to be masked out
  644. '   [hPal]
  645. '           Handle of palette to select into the memory DC's used to create
  646. '           the painting effect.
  647. '           If not provided, a HalfTone palette is used.
  648. '-------------------------------------------------------------------------
  649. Public Sub PaintTransparentStdPic(ByVal hdcDest As Long, _
  650.                                     ByVal xDest As Long, _
  651.                                     ByVal yDest As Long, _
  652.                                     ByVal Width As Long, _
  653.                                     ByVal Height As Long, _
  654.                                     ByVal picSource As Picture, _
  655.                                     ByVal xSrc As Long, _
  656.                                     ByVal ySrc As Long, _
  657.                                     ByVal clrMask As OLE_COLOR, _
  658.                                     Optional ByVal hPal As Long = 0)
  659.     Dim hdcSrc As Long         'HDC that the source bitmap is selected into
  660.     Dim hbmMemSrcOld As Long
  661.     Dim hbmMemSrc As Long
  662.     Dim udtRect As RECT
  663.     Dim hbrMask As Long
  664.     Dim lMaskColor As Long
  665.     Dim hdcScreen As Long
  666.     Dim hPalOld As Long
  667.     'Verify that the passed picture is a Bitmap
  668.     If picSource Is Nothing Then GoTo PaintTransparentStdPic_InvalidParam
  669.     
  670.     Select Case picSource.Type
  671.         Case vbPicTypeBitmap
  672.             hdcScreen = GetDC(0&)
  673.             'Validate palette
  674.             If hPal = 0 Then
  675.                 hPal = m_hpalHalftone
  676.             End If
  677.             'Select passed picture into an HDC
  678.             hdcSrc = CreateCompatibleDC(hdcScreen)
  679.             hbmMemSrcOld = SelectObject(hdcSrc, picSource.handle)
  680.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  681.             RealizePalette hdcSrc
  682.             'Draw the bitmap
  683.             PaintTransparentDC hdcDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, clrMask, hPal
  684.             
  685.             SelectObject hdcSrc, hbmMemSrcOld
  686.             SelectPalette hdcSrc, hPalOld, True
  687.             RealizePalette hdcSrc
  688.             DeleteDC hdcSrc
  689.             ReleaseDC 0&, hdcScreen
  690.         Case vbPicTypeIcon
  691.             'Create a bitmap and select it into an DC
  692.             hdcScreen = GetDC(0&)
  693.             'Validate palette
  694.             If hPal = 0 Then
  695.                 hPal = m_hpalHalftone
  696.             End If
  697.             hdcSrc = CreateCompatibleDC(hdcScreen)
  698.             hbmMemSrc = CreateCompatibleBitmap(hdcScreen, Width, Height)
  699.             hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
  700.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  701.             RealizePalette hdcSrc
  702.             'Draw Icon onto DC
  703.             udtRect.Bottom = Height
  704.             udtRect.Right = Width
  705.             OleTranslateColor clrMask, 0&, lMaskColor
  706.             hbrMask = CreateSolidBrush(lMaskColor)
  707.             FillRect hdcSrc, udtRect, hbrMask
  708.             DeleteObject hbrMask
  709.             DrawIcon hdcSrc, 0, 0, picSource.handle
  710.             'Draw Transparent image
  711.             PaintTransparentDC hdcDest, xDest, yDest, Width, Height, hdcSrc, 0, 0, lMaskColor, hPal
  712.             'Clean up
  713.             DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
  714.             SelectPalette hdcSrc, hPalOld, True
  715.             RealizePalette hdcSrc
  716.             DeleteDC hdcSrc
  717.             ReleaseDC 0&, hdcScreen
  718.         Case Else
  719.             GoTo PaintTransparentStdPic_InvalidParam
  720.     End Select
  721.     Exit Sub
  722. PaintTransparentStdPic_InvalidParam:
  723.     Err.Raise giINVALID_PICTURE
  724.     Exit Sub
  725. End Sub
  726.  
  727. '-------------------------------------------------------------------------
  728. 'Purpose:   Draws a standard picture object to a DC
  729. 'In:
  730. '   [hdcDest]
  731. '           Handle of the device context to paint the picture on
  732. '   [xDest]
  733. '           X coordinate of the upper left corner of the area that the
  734. '           picture is to be painted on. (in pixels)
  735. '   [yDest]
  736. '           Y coordinate of the upper left corner of the area that the
  737. '           picture is to be painted on. (in pixels)
  738. '   [Width]
  739. '           Width of picture area to paint in pixels.  Note: If this value
  740. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  741. '           instead of the pictures' width in pixels), this procedure will
  742. '           attempt to create bitmaps that require outrageous
  743. '           amounts of memory.
  744. '   [Height]
  745. '           Height of picture area to paint in pixels.  Note: If this
  746. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  747. '           twips instead of the pictures' height in pixels), this
  748. '           procedure will attempt to create bitmaps that require
  749. '           outrageous amounts of memory.
  750. '   [picSource]
  751. '           Standard Picture object to be used as the image source
  752. '   [xSrc]
  753. '           X coordinate of the upper left corner of the area in the picture
  754. '           to use as the source. (in pixels)
  755. '           Ignored if picSource is an Icon.
  756. '   [ySrc]
  757. '           Y coordinate of the upper left corner of the area in the picture
  758. '           to use as the source. (in pixels)
  759. '           Ignored if picSource is an Icon.
  760. '   [hPal]
  761. '           Handle of palette to select into the memory DC's used to create
  762. '           the painting effect.
  763. '           If not provided, a HalfTone palette is used.
  764. '-------------------------------------------------------------------------
  765. Public Sub PaintNormalStdPic(ByVal hdcDest As Long, _
  766.                                     ByVal xDest As Long, _
  767.                                     ByVal yDest As Long, _
  768.                                     ByVal Width As Long, _
  769.                                     ByVal Height As Long, _
  770.                                     ByVal picSource As Picture, _
  771.                                     ByVal xSrc As Long, _
  772.                                     ByVal ySrc As Long, _
  773.                                     Optional ByVal hPal As Long = 0)
  774.     Dim hdcTemp As Long
  775.     Dim hPalOld As Long
  776.     Dim hbmMemSrcOld As Long
  777.     Dim hdcScreen As Long
  778.     Dim hbmMemSrc As Long
  779.     'Validate that a bitmap was passed in
  780.     If picSource Is Nothing Then GoTo PaintNormalStdPic_InvalidParam
  781.     Select Case picSource.Type
  782.         Case vbPicTypeBitmap
  783.             If hPal = 0 Then
  784.                 hPal = m_hpalHalftone
  785.             End If
  786.             hdcScreen = GetDC(0&)
  787.             'Create a DC to select bitmap into
  788.             hdcTemp = CreateCompatibleDC(hdcScreen)
  789.             hPalOld = SelectPalette(hdcTemp, hPal, True)
  790.             RealizePalette hdcTemp
  791.             'Select bitmap into DC
  792.             hbmMemSrcOld = SelectObject(hdcTemp, picSource.handle)
  793.             'Copy to destination DC
  794.             BitBlt hdcDest, xDest, yDest, Width, Height, hdcTemp, xSrc, ySrc, vbSrcCopy
  795.             'Cleanup
  796.             SelectObject hdcTemp, hbmMemSrcOld
  797.             SelectPalette hdcTemp, hPalOld, True
  798.             RealizePalette hdcTemp
  799.             DeleteDC hdcTemp
  800.             ReleaseDC 0&, hdcScreen
  801.         Case vbPicTypeIcon
  802.             'Create a bitmap and select it into an DC
  803.             'Draw Icon onto DC
  804.             DrawIconEx hdcDest, xDest, yDest, picSource.handle, Width, Height, 0&, 0&, DI_NORMAL
  805.         Case Else
  806.             GoTo PaintNormalStdPic_InvalidParam
  807.     End Select
  808.     Exit Sub
  809. PaintNormalStdPic_InvalidParam:
  810.     Err.Raise giINVALID_PICTURE
  811. End Sub
  812.  
  813. Private Sub Class_Initialize()
  814.     Dim hdcScreen As Long
  815.     'Create halftone palette
  816.     hdcScreen = GetDC(0&)
  817.     m_hpalHalftone = CreateHalftonePalette(hdcScreen)
  818.     ReleaseDC 0&, hdcScreen
  819. End Sub
  820.  
  821. Private Sub Class_Terminate()
  822.     DeleteObject m_hpalHalftone
  823. End Sub
  824.  
  825. Public Sub PaintTransCornerDC(ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long)
  826.    '
  827.    ' 32-Bit Transparent BitBlt Function
  828.    ' Written by Geoff Glaze 2/13/98
  829.    '
  830.    ' Purpose:
  831.    '    Creates a transparent bitmap using lower left pixel of source bitmap
  832.    '
  833.    ' Parameters ************************************************************
  834.    '   hDestDC:     Destination device context
  835.    '   x, y:        Upper-left destination coordinates (pixels)
  836.    '   nWidth:      Width of destination
  837.    '   nHeight:     Height of destination
  838.    '   hSrcDC:      Source device context
  839.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  840.    ' ***********************************************************************
  841.    
  842.    Dim iBackColor As Long
  843.     
  844.    iBackColor = GetPixel(hSrcDC, 0, 0)
  845.    If iBackColor = CLR_INVALID Then
  846.         'invalid color (specified point is outside of the clipping region)
  847.         'use default grey (standard bitmap back color)
  848.         iBackColor = &HC0C0C0
  849.     End If
  850.    
  851.    PaintTransparentDC hDestDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, iBackColor
  852.    
  853. End Sub
  854.  
  855. Public Sub PaintDisabledCornerDC(ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long)
  856.    '
  857.    ' 32-Bit Transparent BitBlt Function
  858.    ' Written by Geoff Glaze 2/13/98
  859.    '
  860.    ' Purpose:
  861.    '    Creates a transparent bitmap using lower left pixel of source bitmap
  862.    '
  863.    ' Parameters ************************************************************
  864.    '   hDestDC:     Destination device context
  865.    '   x, y:        Upper-left destination coordinates (pixels)
  866.    '   nWidth:      Width of destination
  867.    '   nHeight:     Height of destination
  868.    '   hSrcDC:      Source device context
  869.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  870.    ' ***********************************************************************
  871.    
  872.    Dim iBackColor As Long
  873.     
  874.    iBackColor = GetPixel(hSrcDC, 0, 0)
  875.    If iBackColor = CLR_INVALID Then
  876.         'invalid color (specified point is outside of the clipping region)
  877.         'use default grey (standard bitmap back color)
  878.         iBackColor = &HC0C0C0
  879.     End If
  880.    
  881.    PaintDisabledDC hDestDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, iBackColor
  882.    
  883. End Sub
  884.  
  885. Public Sub PaintTransCornerStdPic(ByVal hdcDest As Long, _
  886.                                     ByVal xDest As Long, _
  887.                                     ByVal yDest As Long, _
  888.                                     ByVal Width As Long, _
  889.                                     ByVal Height As Long, _
  890.                                     ByVal picSource As Picture, _
  891.                                     ByVal xSrc As Long, _
  892.                                     ByVal ySrc As Long, _
  893.                                     Optional ByVal hPal As Long = 0)
  894.    '
  895.    ' 32-Bit Transparent BitBlt Function
  896.    ' Written by Geoff Glaze 2/13/98
  897.    '
  898.    ' Purpose:
  899.    '    Creates a transparent bitmap using lower left pixel of source bitmap
  900.    '
  901.    ' Parameters ************************************************************
  902.    '   hDestDC:     Destination device context
  903.    '   x, y:        Upper-left destination coordinates (pixels)
  904.    '   nWidth:      Width of destination
  905.    '   nHeight:     Height of destination
  906.    '   hSrcDC:      Source device context
  907.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  908.    ' ***********************************************************************
  909.    
  910.     Dim hdcSrc As Long         'HDC that the source bitmap is selected into
  911.     Dim hbmMemSrcOld As Long
  912.     Dim hbmMemSrc As Long
  913.     Dim udtRect As RECT
  914.     Dim hbrMask As Long
  915.     Dim lMaskColor As Long
  916.     Dim hdcScreen As Long
  917.     Dim hPalOld As Long
  918.     'Verify that the passed picture is a Bitmap
  919.     If picSource Is Nothing Then GoTo PaintTransCornerStdPic_InvalidParam
  920.     
  921.     Select Case picSource.Type
  922.         Case vbPicTypeBitmap
  923.             hdcScreen = GetDC(0&)
  924.             'Validate palette
  925.             If hPal = 0 Then
  926.                 hPal = m_hpalHalftone
  927.             End If
  928.             'Select passed picture into an HDC
  929.             hdcSrc = CreateCompatibleDC(hdcScreen)
  930.             hbmMemSrcOld = SelectObject(hdcSrc, picSource.handle)
  931.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  932.             RealizePalette hdcSrc
  933.             
  934.             'get back color
  935.             lMaskColor = GetPixel(hdcSrc, 0, 0)
  936.             If lMaskColor = CLR_INVALID Then
  937.                  'invalid color (specified point is outside of the clipping region)
  938.                  'use default grey (standard bitmap back color)
  939.                  lMaskColor = &HC0C0C0
  940.             End If
  941.             
  942.             'Draw the bitmap
  943.             PaintTransparentDC hdcDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, lMaskColor, hPal
  944.             
  945.             SelectObject hdcSrc, hbmMemSrcOld
  946.             SelectPalette hdcSrc, hPalOld, True
  947.             RealizePalette hdcSrc
  948.             DeleteDC hdcSrc
  949.             ReleaseDC 0&, hdcScreen
  950.         Case vbPicTypeIcon
  951.             'Create a bitmap and select it into an DC
  952.             hdcScreen = GetDC(0&)
  953.             'Validate palette
  954.             If hPal = 0 Then
  955.                 hPal = m_hpalHalftone
  956.             End If
  957.             hdcSrc = CreateCompatibleDC(hdcScreen)
  958.             hbmMemSrc = CreateCompatibleBitmap(hdcScreen, Width, Height)
  959.             hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
  960.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  961.             RealizePalette hdcSrc
  962.             'Draw Icon onto DC
  963.             udtRect.Bottom = Height
  964.             udtRect.Right = Width
  965.             
  966.             'get back color
  967.             lMaskColor = GetPixel(hdcSrc, 0, 0)
  968.             If lMaskColor = CLR_INVALID Then
  969.                  'invalid color (specified point is outside of the clipping region)
  970.                  'use default grey (standard bitmap back color)
  971.                  lMaskColor = &HC0C0C0
  972.             End If
  973.             
  974. '            OleTranslateColor clrMask, 0&, lMaskColor
  975.             hbrMask = CreateSolidBrush(lMaskColor)
  976.             FillRect hdcSrc, udtRect, hbrMask
  977.             DeleteObject hbrMask
  978.             DrawIcon hdcSrc, 0, 0, picSource.handle
  979.             'Draw Transparent image
  980.             PaintTransparentDC hdcDest, xDest, yDest, Width, Height, hdcSrc, 0, 0, lMaskColor, hPal
  981.             'Clean up
  982.             DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
  983.             SelectPalette hdcSrc, hPalOld, True
  984.             RealizePalette hdcSrc
  985.             DeleteDC hdcSrc
  986.             ReleaseDC 0&, hdcScreen
  987.         Case Else
  988.             GoTo PaintTransCornerStdPic_InvalidParam
  989.     End Select
  990.     Exit Sub
  991.  
  992. PaintTransCornerStdPic_InvalidParam:
  993.     Err.Raise giINVALID_PICTURE
  994.     Exit Sub
  995.    
  996. End Sub
  997.  
  998. Public Sub PaintDisabledCornerStdPic(ByVal hdcDest As Long, _
  999.                                     ByVal xDest As Long, _
  1000.                                     ByVal yDest As Long, _
  1001.                                     ByVal Width As Long, _
  1002.                                     ByVal Height As Long, _
  1003.                                     ByVal picSource As Picture, _
  1004.                                     ByVal xSrc As Long, _
  1005.                                     ByVal ySrc As Long, _
  1006.                                     Optional ByVal hPal As Long = 0)
  1007.    '
  1008.    ' 32-Bit Transparent BitBlt Function
  1009.    ' Written by Geoff Glaze 2/13/98
  1010.    '
  1011.    ' Purpose:
  1012.    '    Creates a transparent bitmap using lower left pixel of source bitmap
  1013.    '
  1014.    ' Parameters ************************************************************
  1015.    '   hDestDC:     Destination device context
  1016.    '   x, y:        Upper-left destination coordinates (pixels)
  1017.    '   nWidth:      Width of destination
  1018.    '   nHeight:     Height of destination
  1019.    '   hSrcDC:      Source device context
  1020.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  1021.    ' ***********************************************************************
  1022.    
  1023.     Dim hdcSrc As Long         'HDC that the source bitmap is selected into
  1024.     Dim hbmMemSrcOld As Long
  1025.     Dim hbmMemSrc As Long
  1026.     Dim udtRect As RECT
  1027.     Dim hbrMask As Long
  1028.     Dim lMaskColor As Long
  1029.     Dim hdcScreen As Long
  1030.     Dim hPalOld As Long
  1031.     'Verify that the passed picture is a Bitmap
  1032.     If picSource Is Nothing Then GoTo PaintDisabledCornerStdPic_InvalidParam
  1033.     
  1034.     Select Case picSource.Type
  1035.         Case vbPicTypeBitmap
  1036.             hdcScreen = GetDC(0&)
  1037.             'Validate palette
  1038.             If hPal = 0 Then
  1039.                 hPal = m_hpalHalftone
  1040.             End If
  1041.             'Select passed picture into an HDC
  1042.             hdcSrc = CreateCompatibleDC(hdcScreen)
  1043.             hbmMemSrcOld = SelectObject(hdcSrc, picSource.handle)
  1044.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  1045.             RealizePalette hdcSrc
  1046.             
  1047.             'get back color
  1048.             lMaskColor = GetPixel(hdcSrc, 0, 0)
  1049.             If lMaskColor = CLR_INVALID Then
  1050.                  'invalid color (specified point is outside of the clipping region)
  1051.                  'use default grey (standard bitmap back color)
  1052.                  lMaskColor = &HC0C0C0
  1053.             End If
  1054.             
  1055.             'Draw the bitmap
  1056.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, lMaskColor, , , hPal
  1057.             
  1058.             SelectObject hdcSrc, hbmMemSrcOld
  1059.             SelectPalette hdcSrc, hPalOld, True
  1060.             RealizePalette hdcSrc
  1061.             DeleteDC hdcSrc
  1062.             ReleaseDC 0&, hdcScreen
  1063.         Case vbPicTypeIcon
  1064.             'Create a bitmap and select it into an DC
  1065.             hdcScreen = GetDC(0&)
  1066.             'Validate palette
  1067.             If hPal = 0 Then
  1068.                 hPal = m_hpalHalftone
  1069.             End If
  1070.             hdcSrc = CreateCompatibleDC(hdcScreen)
  1071.             hbmMemSrc = CreateCompatibleBitmap(hdcScreen, Width, Height)
  1072.             hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
  1073.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  1074.             RealizePalette hdcSrc
  1075.             'Draw Icon onto DC
  1076.             udtRect.Bottom = Height
  1077.             udtRect.Right = Width
  1078. '            OleTranslateColor clrMask, 0&, lMaskColor
  1079.             
  1080.             'get back color
  1081.             lMaskColor = GetPixel(hdcSrc, 0, 0)
  1082.             If lMaskColor = CLR_INVALID Then
  1083.                  'invalid color (specified point is outside of the clipping region)
  1084.                  'use default grey (standard bitmap back color)
  1085.                  lMaskColor = &HC0C0C0
  1086.             End If
  1087.  
  1088.             hbrMask = CreateSolidBrush(lMaskColor)
  1089.             FillRect hdcSrc, udtRect, hbrMask
  1090.             DeleteObject hbrMask
  1091.             DrawIcon hdcSrc, 0, 0, picSource.handle
  1092.             'Draw Transparent image
  1093.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hdcSrc, 0, 0, lMaskColor, , , hPal
  1094.             'Clean up
  1095.             DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
  1096.             SelectPalette hdcSrc, hPalOld, True
  1097.             RealizePalette hdcSrc
  1098.             DeleteDC hdcSrc
  1099.             ReleaseDC 0&, hdcScreen
  1100.         Case Else
  1101.             GoTo PaintDisabledCornerStdPic_InvalidParam
  1102.     End Select
  1103.     Exit Sub
  1104.  
  1105. PaintDisabledCornerStdPic_InvalidParam:
  1106.     Err.Raise giINVALID_PICTURE
  1107.     Exit Sub
  1108.    
  1109. End Sub
  1110.  
  1111. Public Sub PaintGreyScaleCornerStdPic(ByVal hdcDest As Long, _
  1112.                                     ByVal xDest As Long, _
  1113.                                     ByVal yDest As Long, _
  1114.                                     ByVal Width As Long, _
  1115.                                     ByVal Height As Long, _
  1116.                                     ByVal picSource As Picture, _
  1117.                                     ByVal xSrc As Long, _
  1118.                                     ByVal ySrc As Long, _
  1119.                                     Optional ByVal hPal As Long = 0)
  1120.    '
  1121.    ' 32-Bit GreyScale BitBlt Function
  1122.    ' Written by Geoff Glaze 2/13/98
  1123.    '
  1124.    ' Purpose:
  1125.    '    Creates a greyscale version of a bitmap
  1126.    '
  1127.    ' Parameters ************************************************************
  1128.    '   hDestDC:     Destination device context
  1129.    '   x, y:        Upper-left destination coordinates (pixels)
  1130.    '   nWidth:      Width of destination
  1131.    '   nHeight:     Height of destination
  1132.    '   hSrcDC:      Source device context
  1133.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  1134.    ' ***********************************************************************
  1135.    
  1136.     Dim hdcSrc As Long         'HDC that the source bitmap is selected into
  1137.     Dim hbmMemSrcOld As Long
  1138.     Dim hbmMemSrc As Long
  1139.     Dim udtRect As RECT
  1140.     Dim hbrMask As Long
  1141.     Dim lMaskColor As Long
  1142.     Dim hdcScreen As Long
  1143.     Dim hPalOld As Long
  1144.     Dim hBrush As Long
  1145.     'Verify that the passed picture is a Bitmap
  1146.     If picSource Is Nothing Then GoTo PaintGreyScaleCornerStdPic_InvalidParam
  1147.     
  1148.     hBrush = CreateSolidBrush(RGB(100, 100, 100))
  1149.     Select Case picSource.Type
  1150.         Case vbPicTypeBitmap
  1151.             Call DrawState(hdcDest, hBrush, 0&, picSource, 0&, xDest, yDest, Width, Height, DST_BITMAP Or DSS_UNION)
  1152.         Case vbPicTypeIcon
  1153.             Call DrawState(hdcDest, hBrush, 0&, picSource, 0&, xDest, yDest, Width, Height, DST_ICON Or DSS_UNION)
  1154.         Case Else
  1155.             GoTo PaintGreyScaleCornerStdPic_InvalidParam
  1156.     End Select
  1157.     Exit Sub
  1158.  
  1159. PaintGreyScaleCornerStdPic_InvalidParam:
  1160.     Err.Raise giINVALID_PICTURE
  1161.     Exit Sub
  1162.    
  1163. End Sub
  1164.  
  1165. Public Function GetRedAmount(ByVal iColor As Long) As Long
  1166.     GetRedAmount = iColor Mod 256
  1167. End Function
  1168.  
  1169. Public Function GetGreenAmount(ByVal iColor As Long) As Long
  1170.     GetGreenAmount = (iColor \ 256) Mod 256
  1171. End Function
  1172.  
  1173. Public Function GetBlueAmount(ByVal iColor As Long) As Long
  1174.     GetBlueAmount = (iColor \ 256 ^ 2) Mod 256
  1175. End Function
  1176.  
  1177. Public Function AverageColors(ByVal iColor1 As Long, iColor2 As Long) As Long
  1178.     Dim xRed As Long
  1179.     Dim xGreen As Long
  1180.     Dim xBlue As Long
  1181.     xRed = (GetRedAmount(iColor1) + GetRedAmount(iColor2)) \ 2
  1182.     xGreen = (GetGreenAmount(iColor1) + GetGreenAmount(iColor2)) \ 2
  1183.     xBlue = (GetBlueAmount(iColor1) + GetBlueAmount(iColor2)) \ 2
  1184.     AverageColors = RGB(xRed, xGreen, xBlue)
  1185. End Function
  1186.  
  1187.  
  1188.